public void execute ( Runnable task , long timeoutMillis ) throws RejectedExecutionException { if ( task == null ) { throw new NullPointerException ( "Cannot accept null task" ) ; } synchronized ( this ) { if ( mState != STATE_RUNNING && mState != STATE_NOT_STARTED ) { throw new RejectedExecutionException ( "Task queue is shutdown" ) ; } } try { if ( ! mQueue . offer ( task , timeoutMillis , TimeUnit . MILLISECONDS ) ) { throw new RejectedExecutionException ( "Unable to enqueue task after waiting " + timeoutMillis + " milliseconds" ) ; } } catch ( InterruptedException e ) { throw new RejectedExecutionException ( e ) ; } }
Enqueue a task to run .