Answers for "how do you know when an executer service is done"

1

how do you know when an executer service is done

ExecutorService executorService = Executors.newFixedThreadPool(10);
executorService.submit(() -> {
  int linesRead = 0;
  while (linesRead < 1000000) {
    System.out.println(linesRead);
    linesRead++;
  }
  System.out.println("lines read: " + linesRead);
  executorService.shutdown();
});

//sleep until executerService has shut itself down
while(executorService.isTerminated() == false) {
	TimeUnit.MILLISECONDS.sleep(10);
}
    
Just have the executorService shut it's self down when it's done and 
loop in the main thread until it's done.
Posted by: Guest on July-12-2021

Code answers related to "how do you know when an executer service is done"

Browse Popular Code Answers by Language