Java 8 PriorityBlockingQueue - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PriorityBlockingQueue class.

This code example shows how to use the following methods:size, take
     * 只有被外部线程中断,才会返回false 
     */ 
    private boolean mmapOperation() { 
        AllocateRequest req = null;
        try { 
            req = this.requestQueue.take();
            if (null == this.requestTable.get(req.getFilePath())) {
                log.warn("this mmap request expired, maybe cause timeout " + req.getFilePath() + " "
                        + req.getFileSize());
                return true; 
            } 
 
            if (req.getMapedFile() == null) {
                long beginTime = System.currentTimeMillis();
                MapedFile mapedFile = new MapedFile(req.getFilePath(), req.getFileSize());
                long eclipseTime = UtilAll.computeEclipseTimeMilliseconds(beginTime);
                // 记录大于10ms的 
                if (eclipseTime > 10) {
                    int queueSize = this.requestQueue.size();
                    log.warn("create mapedFile spent time(ms) " + eclipseTime + " queue size " + queueSize

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        queues.add(new ConcurrentLinkedQueue<Boolean>());
        queues.add(new ArrayBlockingQueue<Boolean>(count, false));
        queues.add(new ArrayBlockingQueue<Boolean>(count, true));
        queues.add(new LinkedBlockingQueue<Boolean>());
        queues.add(new LinkedBlockingDeque<Boolean>());
        queues.add(new PriorityBlockingQueue<Boolean>());
        queues.add(new PriorityQueue<Boolean>());
        queues.add(new LinkedList<Boolean>());
        queues.add(new LinkedTransferQueue<Boolean>());
 
        // Following additional implementations are available from: 
        // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html 
        // queues.add(new SynchronizedLinkedListQueue<Boolean>()); 
 
        // Avoid "first fast, second slow" benchmark effect. 
        Collections.shuffle(queues);
        return queues;
    } 
 
    void prettyPrintResults() { 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isEmpty, peek, poll
   * Indicates whether a not a new result is available. 
   * 
   * @return true if a new result is available, false otherwise. 
   */ 
  public boolean peek() { 
    if (outputQueue.isEmpty()) {
      return false; 
    } else { 
      final int nextId = outputQueue.peek().id;
      return orderResults ? nextId == lastReturnedId + 1 : true;
    } 
  } 
 
  /** 
   * Returns the next available result. 
   * 
   * @return the next completed result, or null if no result is available 
   */ 
  public O poll() { 
    if (!peek()) return null; 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isEmpty
 
    public void writeExternal(ObjectOutput out) throws IOException {
        out.writeLong( timer.get() );
        // this is a work around to a bug in the object stream code, where it raises exceptions 
        // when trying to de-serialize an empty priority queue. 
        out.writeObject( queue.isEmpty() ? null : queue );
    } 
 
    public void setTimerJobFactoryManager(TimerJobFactoryManager timerJobFactoryManager) {
        this.jobFactoryManager = timerJobFactoryManager;
    } 
     
    public TimerJobFactoryManager getTimerJobFactoryManager() { 
        return this.jobFactoryManager;
    }     
 
    /** 
     * @inheritDoc 
     *  
     * @see org.kie.api.time.SessionClock#getCurrentTime() 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        queues.add(new ConcurrentLinkedQueue<Boolean>());
        queues.add(new ArrayBlockingQueue<Boolean>(count, false));
        queues.add(new ArrayBlockingQueue<Boolean>(count, true));
        queues.add(new LinkedBlockingQueue<Boolean>());
        queues.add(new LinkedBlockingDeque<Boolean>());
        queues.add(new PriorityBlockingQueue<Boolean>());
        queues.add(new PriorityQueue<Boolean>());
        queues.add(new LinkedList<Boolean>());
//        queues.add(new LinkedTransferQueue<Boolean>()); 
 
        // Following additional implementations are available from: 
        // http://gee.cs.oswego.edu/dl/concurrency-interest/index.html 
        // queues.add(new SynchronizedLinkedListQueue<Boolean>()); 
 
        // Avoid "first fast, second slow" benchmark effect. 
        Collections.shuffle(queues);
        return queues;
    } 
 
    void prettyPrintResults() { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    void init(Handler handler, int threadPoolSize) {
        mHandler = handler;
        mItemStates = Collections.synchronizedMap(new WeakHashMap<View, ItemState<Params>>());
        mItemRequests = new ConcurrentHashMap<Params, ItemRequest<Params, Result>>(8, 0.9f, 1);
        mExecutorService = new ItemsThreadPoolExecutor<Params, Result>(threadPoolSize, threadPoolSize, 60,
                TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>());
    } 
 
    void performDisplayItem(View itemView, long timestamp) {
        ItemState<Params> itemState = getItemState(itemView);
        if (!itemState.shouldLoadItem) {
            if (ENABLE_LOGGING) {
                Log.d(LOGTAG, "Item should not load, bailing: " + itemState.itemParams);
            } 
 
            return; 
        } 
 
        Params itemParams = itemState.itemParams;
        if (itemParams == null) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
  public static <E extends Comparable> PriorityBlockingQueue<E> newPriorityBlockingQueue(
      Iterable<? extends E> elements) {
    if (elements instanceof Collection) {
      return new PriorityBlockingQueue<E>(Collections2.cast(elements));
    } 
    PriorityBlockingQueue<E> queue = new PriorityBlockingQueue<E>();
    Iterables.addAll(queue, elements);
    return queue;
  } 
 
  // PriorityQueue 
 
  /** 
   * Creates an empty {@code PriorityQueue} with the ordering given by its 
   * elements' natural ordering. 
   * 
   * @since 11.0 (requires that {@code E} be {@code Comparable} since 15.0). 
   */ 
  public static <E extends Comparable> PriorityQueue<E> newPriorityQueue() {
    return new PriorityQueue<E>();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    public BlockingConcurrentWindowCounter(int size) {
        this(size, 0);
    } 
 
    public BlockingConcurrentWindowCounter(int size, int init) {
        this.queue = new PriorityBlockingQueue<Integer>(size);
        this.semaphore = new Semaphore(size);
        this.head = this.tail = init;
    } 
 
    public int incrementAndGet() throws Exception {
        semaphore.acquire();
        synchronized (this) {
            return head++;
        } 
    } 
 
    public int incrementAndGet(long timeout, TimeUnit unit) throws Exception {
        semaphore.tryAcquire(timeout, unit);
        synchronized (this) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add, size
package inescid.gsd.centralizedrollerchain.test; 
 
import inescid.gsd.centralizedrollerchain.utils.PriorityPair; 
 
import java.util.concurrent.PriorityBlockingQueue; 
 
public class PriorityTest { 
 
	public static void main(String[] args) {
		PriorityBlockingQueue<PriorityPair<Integer, Integer>> queue = new PriorityBlockingQueue<PriorityPair<Integer, Integer>>();
 
		queue.add(new PriorityPair<Integer, Integer>(1, 4, 0));
		queue.add(new PriorityPair<Integer, Integer>(2, 4, 0));
		queue.add(new PriorityPair<Integer, Integer>(3, 4, 1));
		queue.add(new PriorityPair<Integer, Integer>(4, 4, 0));
		queue.add(new PriorityPair<Integer, Integer>(5, 4, 0));
		queue.add(new PriorityPair<Integer, Integer>(6, 4, 2));
		queue.add(new PriorityPair<Integer, Integer>(7, 4, 0));
		queue.add(new PriorityPair<Integer, Integer>(8, 4, 0));
 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:iterator, add
            new IceTcpHostPassiveCandidate(relatedAddress, false);
         
        assertTrue(host.getPriority() > relay.getPriority());
         
        final Queue<IceCandidate> candidates = 
            new PriorityBlockingQueue<IceCandidate>(4);
        candidates.add(relay);
        candidates.add(host);
         
        final IceCandidate top = candidates.iterator().next();
        assertEquals(host, top);
        } 
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 PriorityBlockingQueue Methods: