public void execute ( Runnable command ) { adjustPoolSize ( ) ; if ( numProcessors == 1 ) { // if there is only one processor execute with current thread command . run ( ) ; } else { try { executor . execute ( command ) ; } catch ( InterruptedException e ) { // run with current thread instead command . run ( ) ; } } }
Executes the given command . This method will block if all threads in the pool are busy and return only when the command has been accepted . Care must be taken that no deadlock occurs when multiple commands are scheduled for execution . In general commands should not depend on the execution of other commands!