private void executeQueue(OrderedTaskQueue currQueue) { Task t; currQueue.changePool(); t = currQueue.poll(); //submit all tasks in current queue while(t!=null) { activeTasksCount.incrementAndGet(); waitingTasks.offer(t); t = currQueue.poll(); } }
/** * Stops scheduler. */ public void stop() { if (!this.isActive) { return; } coreThread.shutdown(); criticalThread.shutdown(); for(int i=0;i<workerThreads.length;i++) workerThreads[i].shutdown(); for(int i=0;i<criticalWorkerThreads.length;i++) criticalWorkerThreads[i].shutdown(); try { Thread.sleep(40); } catch(InterruptedException e) { } for(int i=0;i<taskQueues.length;i++) taskQueues[i].clear(); for(int i=0;i<heartBeatQueue.length;i++) heartBeatQueue[i].clear(); }
/** * Queues task for execution according to its priority. * * @param task the task to be executed. */ public void submit(Task task,Integer index) { task.activate(false); taskQueues[index].accept(task); }
/** * Creates new instance of scheduler. */ public PriorityQueueScheduler(Clock clock) { this.clock = clock; for(int i=0;i<taskQueues.length;i++) { taskQueues[i]=new OrderedTaskQueue(); } for(int i=0;i<heartBeatQueue.length;i++) { heartBeatQueue[i]=new OrderedTaskQueue(); } coreThread = new CoreThread("scheduler-core"); criticalThread = new CriticalThread("scheduler-critical"); workerThreads=new WorkerThread[Runtime.getRuntime().availableProcessors()*2]; criticalWorkerThreads=new CriticalWorkerThread[Runtime.getRuntime().availableProcessors() / 2]; for(int i=0;i<workerThreads.length;i++) { workerThreads[i] = new WorkerThread("scheduler-worker-" + i); } for(int i=0;i<criticalWorkerThreads.length;i++) { criticalWorkerThreads[i] = new CriticalWorkerThread("scheduler-critical-worker-" + i); } }
/** * Queues task for execution according to its priority. * * @param task the task to be executed. */ public void submitHeatbeat(Task task) { task.activate(true); heartBeatQueue[coreThread.runIndex].accept(task); }
private void executeQueue(OrderedTaskQueue currQueue) { Task t; currQueue.changePool(); t = currQueue.poll(); //submit all tasks in current queue while(t!=null) { activeTasksCount.incrementAndGet(); criticalTasks.offer(t); t = currQueue.poll(); } }