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

The difference between the Runnable and Callable interfaces in Java

What is the difference between using the Runnable and Callable interfaces when designing a concurrent thread in Java, why would you choose one over the other? 14 s 14 See explanation here. The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A … Read more

“implements Runnable” vs “extends Thread” in Java

From what time I’ve spent with threads in Java, I’ve found these two ways to write threads: With implements Runnable: public class MyRunnable implements Runnable { public void run() { //Code } } //Started with a “new Thread(new MyRunnable()).start()” call Or, with extends Thread: public class MyThread extends Thread { public MyThread() { super(“MyThread”); } … Read more