sleep()
so that when the service is shutdown, the interrupt signal will stop the task cleanly. while( true )
loop makes it run forever (daemon) and the sleep will throw an exception when the thread is interrupted so it can be stopped.restart
. This will use a lot more CPU than you want!