Skip to content

Commit 4b77e37

Browse files
baljeet20pivovarit
authored andcommitted
BAEL-1071 Added new example (eugenp#2532)
* BAEL-1071 Runnable vs Callable in Java * BAEL-1071 Runnable vs Callable in Java * BAEL-1071 Runnable vs Callable in Java
1 parent 78e47f1 commit 4b77e37

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.baeldung.concurrent.runnable;
2+
3+
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
public class EventLoggingTask implements Runnable{
8+
private Logger logger = LoggerFactory.getLogger(EventLoggingTask.class);
9+
10+
@Override
11+
public void run() {
12+
13+
String messge="Message read from the event queue";
14+
logger.info("Message read from event queue is "+messge);
15+
16+
}
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.concurrent.runnable;
2+
3+
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
6+
import java.util.concurrent.Future;
7+
8+
public class TaskRunner {
9+
10+
private static ExecutorService executorService;
11+
12+
public static void main(String[] args) {
13+
executeTask();
14+
}
15+
16+
private static void executeTask() {
17+
executorService= Executors.newSingleThreadExecutor();
18+
19+
EventLoggingTask task = new EventLoggingTask();
20+
21+
Future future = executorService.submit(task);
22+
23+
executorService.shutdown();
24+
}
25+
}

0 commit comments

Comments
 (0)