ExecutorService, how to wait for all tasks to finish

What is the simplest way to to wait for all tasks of ExecutorService to finish? My task is primarily computational, so I just want to run a large number of jobs – one on each core. Right now my setup looks like this: ExecutorService es = Executors.newFixedThreadPool(2); for (DataTable singleTable : uniquePhrases) { es.execute(new ComputeDTask(singleTable)); … Read more

Naming threads and thread-pools of ExecutorService

Let’s say I have an application that utilizes the Executor framework as such Executors.newSingleThreadExecutor().submit(new Runnable(){ @Override public void run(){ // do stuff } } When I run this application in the debugger, a thread is created with the following (default) name: Thread[pool-1-thread-1]. As you can see, this isn’t terribly useful and as far as I … Read more

If my interface must return Task what is the best way to have a no-operation implementation?

In the code below, due to the interface, the class LazyBar must return a task from its method (and for argument’s sake can’t be changed). If LazyBars implementation is unusual in that it happens to run quickly and synchronously – what is the best way to return a No-Operation task from the method? I have … Read more