BAEL-1071 Added new example (#2532)

* BAEL-1071 Runnable vs Callable in Java

* BAEL-1071 Runnable vs Callable in Java

* BAEL-1071 Runnable vs Callable in Java
This commit is contained in:
baljeet20 2017-08-31 18:33:42 +05:30 committed by Grzegorz Piwowarek
parent 78e47f104f
commit 4b77e378b7
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package com.baeldung.concurrent.runnable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EventLoggingTask implements Runnable{
private Logger logger = LoggerFactory.getLogger(EventLoggingTask.class);
@Override
public void run() {
String messge="Message read from the event queue";
logger.info("Message read from event queue is "+messge);
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.concurrent.runnable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class TaskRunner {
private static ExecutorService executorService;
public static void main(String[] args) {
executeTask();
}
private static void executeTask() {
executorService= Executors.newSingleThreadExecutor();
EventLoggingTask task = new EventLoggingTask();
Future future = executorService.submit(task);
executorService.shutdown();
}
}