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:
parent
78e47f104f
commit
4b77e378b7
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue