I am new to thread programming in Java and hence this basic question. (I checked, but could not find this question previously asked)
I read that threads can be created either by inheriting the Thread class or by implementing the Runnable interface.
I saw a code which had both to the same class.
public class ThreadExample extends Thread implements Runnable {
}
I was wondering what kind of situation would want this and if there is any advantage to this, what is it.
extending
Threadand implementingRunnableis useless (Threadalready implementsRunnable). You pretty much always want to implementRunnable(and not extendThread). That gives you the flexibility of using aThreaddirectly (not recommended) or using one of the newerThreadPoolimplementations injava.util.concurrent(recommended).