I have a MyThread object which I instantiate when my app is loaded through the server, I mark it as a Daemon thread and then call start() on it. The thread is m
start()
Just to complement with another possible solution for completeness. It may not be as nice though.
final Executor executor = Executors.newSingleThreadExecutor(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { executor.shutdownNow(); } });