I'm having this odd behaviour. My program hangs eventhough I'm setting a time to force terminate it. could anyone point out what this strange behaviour could be?
here is my code where I start the threads
protected void pendingTaskStarter() throws Exception {
ExecutorService service = Executors.newFixedThreadPool(maxThreadNum);
ArrayList<Future<Runnable>> futures = new ArrayList<Future<Runnable>>();
System.out.println("max thread num: " + maxThreadNum);
for(int i=0;i<maxThreadNum;i++){
Thread t = new PendingTaskConsumer();
Future<?> f=service.submit(t);
futures.add((Future<Runnable>) f);
}
for (Future<?> future:futures) {
future.get(5l,TimeUnit.MINUTES); // maximum thread's life is 5min (5l <-- 5 in long )
}
service.shutdownNow();
}
I am 100% sure that my program hangs somewhere in PendingTaskConsumer
class based on the outputs within PendingTaskConsumer
class.
Anyways codes in PendingTaskConsumer should be irrelevant as thread is supposedly forced to be terminated. My question is in what scenraios the following line does not do as its expected.
future.get(5l,TimeUnit.MINUTES);
The program is running on Linux(Ubuntu)
and using openjdk-7-jdk backage ( version 1.7)