java - Thread delays during termination -


//main.java public static boolean isend() {     return end; } public static void main(string[] args) {      execproductnumber.execute(new productnumber(allbuffer));      end = true;     system.out.println("leaving main");     //execproductnumber.shutdown(); }  //productnumber.java public void run() {     while(!main.isend()) {         //something     }     system.out.println("leaving thread"); } 

i starting program, gets output:

leaving main leaving thread 

and program not terminate (i need wait 1,5 min successful end of program). when tried stop thread shutdown() (comment) stopped right after. while trying debug found delays on that(threadpoolexecutor.java):

final void runworker(worker w) {         thread wt = thread.currentthread();         runnable task = w.firsttask;         w.firsttask = null;         w.unlock(); // allow interrupts         boolean completedabruptly = true;         try {             while (task != null || (task = gettask()) != null) { //here                 w.lock();                 // if pool stopping, ensure thread interrupted;                 // if not, ensure thread not interrupted.                  // requires recheck in second case deal                 // shutdownnow race while clearing interrupt 

waits there time , moves on. why? happens there? necessary?

if execproductnumber executorservice, need call shutdown() after last job submitted service. will allow submitted jobs finish.

and program not terminate immediately

right. reaching end of main() thread associated executorservice non-daemon , still running. calling execproductnumber.shutdown();, application finish after productnumber task completes.

while trying debug found delays on that(threadpoolexecutor.java):

right, worker threads waiting patiently task submitted thread-pool.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -