thanks for replying. i was creating a library. so it will not know when to call executor.shutdown()
unless the user of the library explicitly calls the shutdown()
. Anyway i got the solution. I made the executor a daemon thread so that it will get killed automatically when the main program exits. code to make a daemon executor is given below
scheduler = Executors.newScheduledThreadPool(maxSize,new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setDaemon(true);
return t;
}
});
Thank you guys. Hope this will help someone