public void schedule ( TimerTask task , boolean checkIfAlreadyPresent ) { final TimerTaskData taskData = task . getData ( ) ; final Serializable taskID = taskData . getTaskID ( ) ; task . setScheduler ( this ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Scheduling task with id " + taskID ) ; } // store the task and data final TimerTaskCacheData timerTaskCacheData = new TimerTaskCacheData ( taskID , baseFqn , cluster ) ; if ( timerTaskCacheData . create ( ) ) { timerTaskCacheData . setTaskData ( taskData ) ; } else if ( checkIfAlreadyPresent ) { throw new IllegalStateException ( "timer task " + taskID + " already scheduled" ) ; } // schedule task final SetTimerAfterTxCommitRunnable setTimerAction = new SetTimerAfterTxCommitRunnable ( task , this ) ; if ( txManager != null ) { try { Transaction tx = txManager . getTransaction ( ) ; if ( tx != null ) { TransactionContext txContext = TransactionContextThreadLocal . getTransactionContext ( ) ; if ( txContext == null ) { txContext = new TransactionContext ( ) ; tx . registerSynchronization ( new TransactionSynchronization ( txContext ) ) ; } txContext . put ( taskID , setTimerAction ) ; task . setSetTimerTransactionalAction ( setTimerAction ) ; } else { setTimerAction . run ( ) ; } } catch ( Throwable e ) { remove ( taskID , true ) ; throw new RuntimeException ( "Unable to register tx synchronization object" , e ) ; } } else { setTimerAction . run ( ) ; } }
Schedules the specified task .