public void start ( ) { switch ( WORKER_STATE_UPDATER . get ( this ) ) { case WORKER_STATE_INIT : if ( WORKER_STATE_UPDATER . compareAndSet ( this , WORKER_STATE_INIT , WORKER_STATE_STARTED ) ) { workerThread . start ( ) ; } break ; case WORKER_STATE_STARTED : break ; case WORKER_STATE_SHUTDOWN : throw new IllegalStateException ( "cannot be started once stopped" ) ; default : throw new Error ( "Invalid WorkerState" ) ; } // Wait until the startTime is initialized by the worker. while ( startTime == 0 ) { try { startTimeInitialized . await ( ) ; } catch ( InterruptedException ignore ) { // Ignore - it will be ready very soon. } } }
Starts the background thread explicitly . The background thread will start automatically on demand even if you did not call this method .