Reputation: 1
I am facing some issue where executer service gets hanged up.
I wanted to test some scenario where one of runnable thread gets stuck as it involves with lot of systems and ultimately leads to executer hangup.
For that I created one testing scenerio where i created 5 threads through executer service and write an infinite loop in one of the thread.I see the code is getting stuck in that loop and not comming to shutdown/shoutDownNow method of main thread. What will be the priority of the main thread execution. How can we enforce shutdown in this case?
Upvotes: 0
Views: 87
Reputation: 164
We can not enforce shut down until any of the runnable task is still in progress (non-daemon thread). You can try loop with large iterations and see. eg.
ExecutorService e = Executors.newCachedThreadPool();
e.execute(new Runnable() {
@Override
public void run() {
for(int i =0 ; i< 5000; i++){
System.out.println("run me in a different thread" + i);
}
}
});
e.shutdown();
Upvotes: 1