/** {@inheritDoc} */ public void runTask(KernelRunnable task, Identity owner) throws Exception { if (isShutdown) { throw new IllegalStateException("Scheduler is shutdown"); } if (ContextResolver.isCurrentTransaction()) { // we're already active in a transaction, so just run the task task.run(); } else { // we're starting a new transaction ScheduledTaskImpl scheduledTask = new ScheduledTaskImpl(task, owner, defaultPriority, System.currentTimeMillis()); waitForTask(scheduledTask, false); } }
/** * Package-private method that runs the given task in a transaction that is not bound by any * timeout value (i.e., is bound only by the {@code com.sun.sgs.txn.timeout.unbounded} property * value). * * @param task the {@code KernelRunnable} to run transactionally * @param owner the {@code Identity} that owns the task * @throws IllegalStateException if this method is called from an actively running transaction * @throws Exception if there is any failure that does not result in re-trying the task */ void runUnboundedTask(KernelRunnable task, Identity owner) throws Exception { if (isShutdown) { throw new IllegalStateException("Scheduler is shutdown"); } if (ContextResolver.isCurrentTransaction()) { throw new IllegalStateException("Cannot be called from within " + "an active transaction"); } // NOTE: in the current system we only use this method once, and // that's when the application is initialized, in which case there // is no other task trying to run...if we decide to start using // this method more broadly, then it should probably use a separate // thread-pool so that it doesn't affect transaction latency ScheduledTaskImpl scheduledTask = new ScheduledTaskImpl(task, owner, defaultPriority, System.currentTimeMillis()); waitForTask(scheduledTask, true); }