Beispiel #1
0
 internal ScheduledJobHandle(TimeBasedTaskScheduler scheduler, Group group, ThreadStart task, long nextDeadlineNanos, long reschedulingDelayNanos)
 {
     this._group            = group;
     this.NextDeadlineNanos = nextDeadlineNanos;
     _handleRelease         = new BinaryLatch();
     _cancelListeners       = new CopyOnWriteArrayList <CancelListener>();
     this._task             = () =>
     {
         try
         {
             task.run();
             // Use compareAndSet to avoid overriding any cancellation state.
             if (compareAndSet(SUBMITTED, RUNNABLE) && reschedulingDelayNanos > 0)
             {
                 // We only reschedule if the rescheduling delay is greater than zero.
                 // A rescheduling delay of zero means this is a delayed task.
                 // If the rescheduling delay is greater than zero, then this is a recurring task.
                 this.NextDeadlineNanos += reschedulingDelayNanos;
                 scheduler.EnqueueTask(this);
             }
         }
         catch (Exception e)
         {
             _lastException = e;
             set(FAILED);
         }
     };
 }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _clock     = new FakeClock();
            _pools     = new ThreadPoolManager(new ThreadGroup("TestPool"));
            _scheduler = new TimeBasedTaskScheduler(_clock, _pools);
            _counter   = new AtomicInteger();
            _semaphore = new Semaphore(0);
        }
Beispiel #3
0
        protected internal CentralJobScheduler()
        {
            _workStealingExecutors = new ConcurrentDictionary <Group, ExecutorService>(1);
            _topLevelGroup         = new TopLevelGroup();
            _pools = new ThreadPoolManager(_topLevelGroup);
            ThreadFactory threadFactory = new GroupedDaemonThreadFactory(Group.TASK_SCHEDULER, _topLevelGroup);

            _scheduler = new TimeBasedTaskScheduler(Clocks.nanoClock(), _pools);

            // The scheduler thread runs at slightly elevated priority for timeliness, and is started in init().
            _schedulerThread = threadFactory.newThread(_scheduler);
            int priority = Thread.NORM_PRIORITY + 1;

            _schedulerThread.Priority = priority;
        }