zuned485
BAN USER- 0of 0 votes
AnswersWhat will be the output on single core machine? Does worker 1 will keep on printing or two thread keeps on context switching among themselves.
- zuned485 in United Statesimport java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class SimpleThreadPool { static class WorkerThread implements Runnable { private String command; public WorkerThread(String s){ this.command=s; } @Override public void run() { while(true){ System.out.println(Thread.currentThread().getName()+" Start. Command = "+command); } } private void processCommand() { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } @Override public String toString(){ return this.command; } } public static void main(String[] args) { ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(new WorkerThread("Worker Thread 1")); executor.execute(new WorkerThread("Worker Thread 2")); executor.shutdown(); while (!executor.isTerminated()) { } System.out.println("Finished all threads"); } }
| Report Duplicate | Flag | PURGE
- zuned485 August 30, 2017