Is this good OO Design assuming you want every inheriting class to be a infinite Thread ? Any better/more elegant way of doing similar thing?
public abstract class Base implements Runnable {
protected abstract void doSomething();
public void run() {
while ( true ) {
Thread.sleep(1000);
doSomething();
}
}
}
If you only want
doSomethingto execute every second, you could move the task to its ownRunnableandscheduleit with aScheduledExecutorService. This way you can reduce the number of threads in your program and save resources.