java - Wait for Executors -
there loop borrow objects genericobjectpool , submit executor in each loop. then, caller has wait exectuors complete.
here nowadays code -
private implclass implobject; private future future; (iterator iter = anarraylist.iterator(); iter.hasnext();) { //gets genericobjectpool object implobject = (implclass) this.getimplpool().borrowobject(); future = getexecutorservices().submit(implobject); } // wait exectuor finish while (!future.isdone()) { seek { thread.sleep(global.waittime()); } grab (interruptedexception iex) { } }
but wrong future waits lastly thread. should create array of futures monitor each executor ?
executorservice has specific method that: executorservice.invokeall(tasks)
the executorcompletionservice mentioned in ralf's reply can helpful - allows process results caller thread arrive.
java multithreading executorservice
No comments:
Post a Comment