List of usage examples for java.util.concurrent PriorityBlockingQueue PriorityBlockingQueue
public PriorityBlockingQueue(int initialCapacity, Comparator<? super E> comparator)
From source file:Main.java
/** * Creates a fixed priority thread pool, sorted with the given comparator. */// ww w . jav a 2 s . co m public static ExecutorService newPriorityThreadPool(String name, int numThreads, Comparator<Runnable> comparator) { return new ThreadPoolExecutor(numThreads, numThreads, 1, TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>(numThreads, comparator), newNamedThreadFactory(name)); }
From source file:org.wso2.carbon.bpmn.people.substitution.scheduler.SchedulerThread.java
SchedulerThread(ScheduledTaskRunner runner) {
_todo = new PriorityBlockingQueue<ScheduledTask>(TODO_QUEUE_INITIAL_CAPACITY, new ComparatorByDate());
_taskrunner = runner;
}
From source file:org.apache.ode.scheduler.simple.SchedulerThread.java
SchedulerThread(TaskRunner runner) {
_todo = new PriorityBlockingQueue<Task>(TODO_QUEUE_INITIAL_CAPACITY, new JobComparatorByDate());
_taskrunner = runner;
}
From source file:org.opencredo.couchdb.inbound.CouchDbChangesPollingMessageSource.java
/** * Creates an instance with a custom CouchDbChangesOperations. *///from ww w .j a va 2s.c o m public CouchDbChangesPollingMessageSource(CouchDbChangesOperations couchDbChangesOperations) { this.couchDbChangesOperations = couchDbChangesOperations; this.toBeReceived = new PriorityBlockingQueue<ChangedDocument>(DEFAULT_INTERNAL_QUEUE_CAPACITY, new Comparator<ChangedDocument>() { public int compare(ChangedDocument doc1, ChangedDocument doc2) { long diff = doc1.getSequence() - doc2.getSequence(); if (diff == 0) { return 0; } else { return diff > 0 ? 1 : -1; } } }); }
From source file:org.apache.geode.geospatial.client.ActorController.java
public void run() { final PriorityBlockingQueue<Actor> priorityQueue = new PriorityBlockingQueue<>(numberOfActors, (Comparator<Actor>) (o1, o2) -> (int) (o1.timeToAdvance() - o2.timeToAdvance())); //Slam in a couple tracks to keep the simulators busy int initialCount = numberOfSimulators * 2; for (int i = 0; i < initialCount; i++) { addActorToQueue(priorityQueue, i); }/*from w ww . j av a2 s . co m*/ for (int i = 0; i < numberOfSimulators; i++) { new Thread(() -> { while (true) { Actor actor = priorityQueue.poll(); long currentDelay = actor.timeToAdvance() - System.currentTimeMillis(); actorDelay.update(currentDelay); if (currentDelay <= 0) { try { actor.advance(); Coordinate coordinate = actor.currentEvent(); LocationEvent locationEvent = new LocationEvent(coordinate.y, coordinate.x, actor.getUid()); geoRegion.put(locationEvent.getUid(), locationEvent); } catch (Exception e) { logger.error(e.getMessage(), e); } priorityQueue.add(actor); } else { priorityQueue.add(actor); try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } for (int i = initialCount; i < numberOfActors; i++) { //Now slowly trickle in more actors until we get up to the number of requested actors. //if we don't trickle them in then they are clustered at various starting points. try { Thread.sleep(newActorTimeout); } catch (InterruptedException e) { e.printStackTrace(); } addActorToQueue(priorityQueue, i); if (i % 1000 == 0) { logger.info("Injected {} drivers @ {}", i, new Date()); } } }
From source file:com.sworddance.taskcontrol.TaskControl.java
@SuppressWarnings("unchecked") public TaskControl(Comparator<PrioritizedTask> activeComparator, int maxThreads, ThreadFactory threadFactory, Log log) {/*w w w. ja va 2 s.c om*/ this.log = log; ApplicationIllegalArgumentException.notNull(activeComparator, "activeComparator"); this.eligibleTasks = new PriorityBlockingQueue<PrioritizedTask>(20, activeComparator); this.stateChangeNotificator = new ReentrantLock(); this.newTasks = this.stateChangeNotificator.newCondition(); this.runningTasks = new AtomicInteger(0); this.threadFactory = threadFactory; int keepAliveTime = 10; int corePoolSize = 1; this.executor = new ThreadPoolExecutor(corePoolSize, Math.max(corePoolSize, maxThreads), keepAliveTime, MICROSECONDS, (BlockingQueue) this.eligibleTasks, threadFactory); this.stayActive = true; }
From source file:com.intel.cosbench.controller.service.COSBControllerService.java
public void init() { if (this.context == null) { LOGGER.error("Controller Context is not initialized."); System.exit(-1);//from w w w .j a va2s . co m } // initialize workload archiver and loader String archive_dir = context.getArchive_dir(); archiver = new SimpleWorkloadArchiver(archive_dir); loader = new SimpleWorkloadLoader(archive_dir); count = new AtomicInteger(archiver.getTotalWorkloads()); order = new AtomicInteger(0); processors = new HashMap<String, WorkloadProcessor>(); processors = Collections.synchronizedMap(processors); int concurrency = context.getConcurrency(); executor = new OrderThreadPoolExecutor(concurrency, concurrency, 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>(memRepo.getMaxCapacity(), new OrderFutureComparator())); }
From source file:org.apache.tajo.master.scheduler.SimpleScheduler.java
@VisibleForTesting public SimpleScheduler(TajoMaster.MasterContext context, TajoRMContext rmContext) { super(SimpleScheduler.class.getName()); this.masterContext = context; this.rmContext = rmContext; //Copy default array capacity from PriorityBlockingQueue. this.queryQueue = new PriorityBlockingQueue<>(11, COMPARATOR); this.queryProcessor = new Thread(new QueryProcessor()); }
From source file:org.opencredo.cloud.storage.si.adapter.ReadingMessageSource.java
/** * @param template//from w w w. ja v a 2 s .c o m * @param containerName * @param filter * @param comparator */ public ReadingMessageSource(final StorageOperations template, String containerName, final BlobDetailsFilter filter, final BlobDetailsComparator comparator) { Assert.notNull(template, "'template' should not be null"); Assert.notNull(filter, "'filter' should not be null"); Assert.notNull(comparator, "'comparator' should not be null"); this.template = template; this.containerName = containerName; this.filter = filter; this.toBeReceived = new PriorityBlockingQueue<BlobDetails>(INTERNAL_QUEUE_CAPACITY, comparator); }
From source file:org.apache.hadoop.hbase.replication.regionserver.RecoveredReplicationSource.java
public void locateRecoveredPaths(PriorityBlockingQueue<Path> queue) throws IOException { boolean hasPathChanged = false; PriorityBlockingQueue<Path> newPaths = new PriorityBlockingQueue<Path>(queueSizePerGroup, new LogsComparator()); pathsLoop: for (Path path : queue) { if (fs.exists(path)) { // still in same location, don't need to do anything newPaths.add(path);/*from www. jav a 2s. com*/ continue; } // Path changed - try to find the right path. hasPathChanged = true; if (stopper instanceof ReplicationSyncUp.DummyServer) { // In the case of disaster/recovery, HMaster may be shutdown/crashed before flush data // from .logs to .oldlogs. Loop into .logs folders and check whether a match exists Path newPath = getReplSyncUpPath(path); newPaths.add(newPath); continue; } else { // See if Path exists in the dead RS folder (there could be a chain of failures // to look at) List<String> deadRegionServers = this.replicationQueueInfo.getDeadRegionServers(); LOG.info("NB dead servers : " + deadRegionServers.size()); final Path walDir = FSUtils.getWALRootDir(conf); for (String curDeadServerName : deadRegionServers) { final Path deadRsDirectory = new Path(walDir, AbstractFSWALProvider.getWALDirectoryName(curDeadServerName)); Path[] locs = new Path[] { new Path(deadRsDirectory, path.getName()), new Path(deadRsDirectory.suffix(AbstractFSWALProvider.SPLITTING_EXT), path.getName()) }; for (Path possibleLogLocation : locs) { LOG.info("Possible location " + possibleLogLocation.toUri().toString()); if (manager.getFs().exists(possibleLogLocation)) { // We found the right new location LOG.info("Log " + path + " still exists at " + possibleLogLocation); newPaths.add(possibleLogLocation); continue pathsLoop; } } } // didn't find a new location LOG.error(String.format("WAL Path %s doesn't exist and couldn't find its new location", path)); newPaths.add(path); } } if (hasPathChanged) { if (newPaths.size() != queue.size()) { // this shouldn't happen LOG.error("Recovery queue size is incorrect"); throw new IOException("Recovery queue size error"); } // put the correct locations in the queue // since this is a recovered queue with no new incoming logs, // there shouldn't be any concurrency issues queue.clear(); for (Path path : newPaths) { queue.add(path); } } }