當前位置: 首頁>>代碼示例>>Java>>正文


Java PriorityBlockingQueue類代碼示例

本文整理匯總了Java中java.util.concurrent.PriorityBlockingQueue的典型用法代碼示例。如果您正苦於以下問題:Java PriorityBlockingQueue類的具體用法?Java PriorityBlockingQueue怎麽用?Java PriorityBlockingQueue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PriorityBlockingQueue類屬於java.util.concurrent包,在下文中一共展示了PriorityBlockingQueue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: newAnimationExecutor

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
/**
 * Returns a new cached thread pool with the given thread count and
 * {@link UncaughtThrowableStrategy} to use when loading frames of animations.
 */
// Public API.
@SuppressWarnings("WeakerAccess")
public static GlideExecutor newAnimationExecutor(
    int threadCount, UncaughtThrowableStrategy uncaughtThrowableStrategy) {
   return new GlideExecutor(
      new ThreadPoolExecutor(
          0 /* corePoolSize */,
          threadCount,
          KEEP_ALIVE_TIME_MS,
          TimeUnit.MILLISECONDS,
          new PriorityBlockingQueue<Runnable>(),
          new DefaultThreadFactory(
              ANIMATION_EXECUTOR_NAME,
              uncaughtThrowableStrategy,
              true)));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:GlideExecutor.java

示例2: testPriorityQueue

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public void testPriorityQueue() throws Exception {
    PriorityBlockingQueue<Priority> queue = new PriorityBlockingQueue<>();
    List<Priority> priorities = Arrays.asList(Priority.values());
    Collections.shuffle(priorities, random());

    for (Priority priority : priorities) {
        queue.add(priority);
    }

    Priority prevPriority = null;
    while (!queue.isEmpty()) {
        if (prevPriority == null) {
            prevPriority = queue.poll();
        } else {
            assertThat(queue.poll().after(prevPriority), is(true));
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:PrioritizedExecutorsTests.java

示例3: testGet_concurrent

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public void testGet_concurrent() {
  assertTrue(ArbitraryInstances.get(BlockingDeque.class).isEmpty());
  assertTrue(ArbitraryInstances.get(BlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(DelayQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(SynchronousQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(PriorityBlockingQueue.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentMap.class).isEmpty());
  assertTrue(ArbitraryInstances.get(ConcurrentNavigableMap.class).isEmpty());
  ArbitraryInstances.get(Executor.class).execute(ArbitraryInstances.get(Runnable.class));
  assertNotNull(ArbitraryInstances.get(ThreadFactory.class));
  assertFreshInstanceReturned(
      BlockingQueue.class, BlockingDeque.class, PriorityBlockingQueue.class,
      DelayQueue.class, SynchronousQueue.class,
      ConcurrentMap.class, ConcurrentNavigableMap.class,
      AtomicReference.class, AtomicBoolean.class,
      AtomicInteger.class, AtomicLong.class, AtomicDouble.class);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:ArbitraryInstancesTest.java

示例4: getExecutor

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public XExecutor getExecutor() {
    if (executor == null) {
        synchronized (DownloadThreadPool.class) {
            if (executor == null) {
                executor = new XExecutor(corePoolSize,
                        MAX_POOL_SIZE,
                        KEEP_ALIVE_TIME,
                        UNIT,
                        new PriorityBlockingQueue<Runnable>()/*無限容量的緩衝隊列*/,
                        Executors.defaultThreadFactory()/*線程創建工廠*/,
                        new ThreadPoolExecutor.AbortPolicy()/*繼續超出上限的策略,阻止*/);
            }
        }
    }

    return executor;
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:18,代碼來源:DownloadThreadPool.java

示例5: ThreadTask

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
private ThreadTask()
{
    final long keepAliveTime = 60L;
    taskCompare = new TaskCompare();
    dbThreadQueue = new PriorityBlockingQueue<PrioriTask>(dbThreadCount,
            taskCompare);
    netThreadQueue = new PriorityBlockingQueue<PrioriTask>(netThreadCount,
            taskCompare);
    otherThreadQueue = new PriorityBlockingQueue<PrioriTask>(dbThreadCount,
            taskCompare);
    dbThreadPool = new ThreadPoolExecutor(dbThreadCount, dbThreadCount, 0L,
            TimeUnit.MILLISECONDS, dbThreadQueue);
    netThreadPool = new ThreadPoolExecutor(netThreadCount, netThreadCount,
            0L, TimeUnit.MILLISECONDS, netThreadQueue);
    otherThreadPool = new ThreadPoolExecutor(otherThreadCount,
            Integer.MAX_VALUE, keepAliveTime, TimeUnit.SECONDS,
            otherThreadQueue);
}
 
開發者ID:RealMoMo,項目名稱:72GGames_Demo,代碼行數:19,代碼來源:ThreadTask.java

示例6: BlockchainManager

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public BlockchainManager(CrypDist crypDist, byte[] session_key)
{
    this.crypDist = crypDist;
    dbManager = new PostgresDB("blockchain", "postgres", "", false);
    serverAccessor = new ServerAccessor();
    transactionPendingBucket = new ConcurrentHashMap<>();
    transactionBucket = new PriorityBlockingQueue<>();
    transactionBucket_solid = new ArrayList<>(BLOCK_SIZE);
    buildBlockchain();
    hashes = new ConcurrentHashMap<>();
    numOfPairs = 0;
    serverTime = getServerTime();
    systemTime = System.currentTimeMillis();
    updating = false;
    Timer timer = new Timer();
    timer.schedule(new BlockchainBatch(),0, Config.BLOCKCHAIN_BATCH_PERIOD);
}
 
開發者ID:CrypDist,項目名稱:CrypDist,代碼行數:18,代碼來源:BlockchainManager.java

示例7: calculaCosteAtencionVictimasFinalesAsignadas

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public double calculaCosteAtencionVictimasFinalesAsignadas(double factorMultiplicativo, VictimsToRescue victims2R, MisObjetivos misObjs){

		double tiempo = 0;     //Variable para calcular el tiempo

    	PriorityBlockingQueue <Objetivo> colaobjetivos = misObjs.getMisObjetivosPriorizados();
    	int tamaniocola = colaobjetivos.size();

    	Iterator<Objetivo> it = colaobjetivos.iterator();

        if (tamaniocola==0){
        	return 0;
        }

    	while (it.hasNext()){
  		  //Hay al menos un objetivo
  	      Objetivo ob = it.next();
  	      String referenciaIdObjetivo = ob.getobjectReferenceId();

	      //Obtener la victima de la cola
	      Victim victimaActualCola = victims2R.getVictimToRescue(referenciaIdObjetivo);    	          	      
	      int prioridadVictimaActualCola = victimaActualCola.getPriority();
	      
	      tiempo = tiempo + (factorMultiplicativo*prioridadVictimaActualCola);
    	}    	    	    	
    	return tiempo;
	}
 
開發者ID:Yarichi,項目名稱:Proyecto-DASI,代碼行數:27,代碼來源:Coste.java

示例8: init

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
/**
 * Initial MiniDownloader.
 *
 * @param context
 */
public void init(Context context) {
    this.appContext = context.getApplicationContext();
    /** Create work executor. */
    this.workExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(), 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>()) {
        @Override
        protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
            if (callable instanceof CustomFutureCallable) {
                return ((CustomFutureCallable) callable).newTaskFor();
            }
            return super.newTaskFor(callable);
        }
    };
    /** Create command executor. */
    this.commandExecutor = Executors.newSingleThreadExecutor();
    /** Create and initial task manager. */
    taskManager = new TaskManager();
    taskManager.init(context);
    /** Create and start ProgressUpdater. */
    progressUpdater = new ProgressUpdater();
    progressUpdater.start();
}
 
開發者ID:xyhuangjinfu,項目名稱:MiniDownloader,代碼行數:27,代碼來源:MiniDownloader.java

示例9: buildQueue

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
/**
 * 構建隊列
 *
 * @param size
 *         隊列大小
 * @param isPriority
 *         是否優先級隊列
 * @return 隊列
 */
public static BlockingQueue<Runnable> buildQueue(int size, boolean isPriority) {
    BlockingQueue<Runnable> queue;
    if (size == 0) { // 默認無隊列
        queue = new SynchronousQueue<Runnable>();
    } else { // 有限隊列或無限隊列
        if (isPriority) {
            queue = size < 0 ? new PriorityBlockingQueue<Runnable>()
                    : new PriorityBlockingQueue<Runnable>(size);
        } else {
            queue = size < 0 ? new LinkedBlockingQueue<Runnable>()
                    : new LinkedBlockingQueue<Runnable>(size);
        }
    }
    return queue;
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:25,代碼來源:ThreadPoolUtils.java

示例10: logSensorDataOnChange

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
/**
 * Store sensor data so that it can be published in the next publishing cycle. Unlike
 * the other log methods, this method saves the {@link #BUFFER_SIZE_FOR_ONCHANGE_SENSORS} most
 * recent sensor readings per sensor type.
 * @param data
 */
public void logSensorDataOnChange(SensorData data) {
    PriorityBlockingQueue<SensorData> newQueue =
            new PriorityBlockingQueue<SensorData>(BUFFER_SIZE_FOR_ONCHANGE_SENSORS,
                    new Comparator<SensorData>() {
        @Override
        public int compare(SensorData o1, SensorData o2) {
            return Long.compare(o1.getTimestamp(), o2.getTimestamp());
        }
    });
    PriorityBlockingQueue<SensorData> lastData = mOnChangeData.putIfAbsent(
            data.getSensorName(), newQueue);

    if (lastData == null) {
        lastData = newQueue;
    }

    // remove old entries if necessary
    while (lastData.size() >= BUFFER_SIZE_FOR_ONCHANGE_SENSORS) {
       lastData.poll();
    }

    lastData.offer(data);
}
 
開發者ID:androidthings,項目名稱:sensorhub-cloud-iot,代碼行數:30,代碼來源:CloudPublisherService.java

示例11: testRetainAll

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    PriorityBlockingQueue q = populatedQueue(SIZE);
    PriorityBlockingQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:PriorityBlockingQueueTest.java

示例12: main

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public static void main(String[] args) {
    final Comparator<String> firstChar = new Comparator<>() {
        public int compare(String x, String y) {
            return x.charAt(0) - y.charAt(0); }};

    test(new PriorityQueue<String>(firstChar));
    test(new PriorityQueue<String>(10, firstChar));
    test(new PriorityBlockingQueue<String>(10, firstChar));
    test(new ArrayBlockingQueue<String>(10));
    test(new LinkedBlockingQueue<String>(10));
    test(new LinkedBlockingDeque<String>(10));
    test(new LinkedTransferQueue<String>());
    test(new ArrayDeque<String>(10));

    System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
    if (failed > 0) throw new Error("Some tests failed");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:RemoveContains.java

示例13: main

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
     final int maxConsumers = (args.length > 0)
         ? Integer.parseInt(args[0])
         : 5;

     pool = Executors.newCachedThreadPool();
     for (int i = 1; i <= maxConsumers; i += (i+1) >>> 1) {
         // Adjust iterations to limit typical single runs to <= 10 ms;
         // Notably, fair queues get fewer iters.
         // Unbounded queues can legitimately OOME if iterations
         // high enough, but we have a sufficiently low limit here.
         run(new ArrayBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingDeque<Integer>(100), i, 1000);
         run(new LinkedTransferQueue<Integer>(), i, 700);
         run(new PriorityBlockingQueue<Integer>(), i, 1000);
         run(new SynchronousQueue<Integer>(), i, 300);
         run(new SynchronousQueue<Integer>(true), i, 200);
         run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
     }
     pool.shutdown();
     if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
         throw new Error();
     pool = null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:SingleProducerMultipleConsumerLoops.java

示例14: main

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
     final int maxPairs = (args.length > 0)
         ? Integer.parseInt(args[0])
         : 5;
     int iters = 10000;

     pool = Executors.newCachedThreadPool();
     for (int i = 1; i <= maxPairs; i += (i+1) >>> 1) {
         // Adjust iterations to limit typical single runs to <= 10 ms;
         // Notably, fair queues get fewer iters.
         // Unbounded queues can legitimately OOME if iterations
         // high enough, but we have a sufficiently low limit here.
         run(new ArrayBlockingQueue<Integer>(100), i, 500);
         run(new LinkedBlockingQueue<Integer>(100), i, 1000);
         run(new LinkedBlockingDeque<Integer>(100), i, 1000);
         run(new LinkedTransferQueue<Integer>(), i, 1000);
         run(new PriorityBlockingQueue<Integer>(), i, 1000);
         run(new SynchronousQueue<Integer>(), i, 400);
         run(new SynchronousQueue<Integer>(true), i, 300);
         run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
     }
     pool.shutdown();
     if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
         throw new Error();
     pool = null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ProducerConsumerLoops.java

示例15: main

import java.util.concurrent.PriorityBlockingQueue; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    final int maxProducers = (args.length > 0)
        ? Integer.parseInt(args[0])
        : 5;

    pool = Executors.newCachedThreadPool();
    for (int i = 1; i <= maxProducers; i += (i+1) >>> 1) {
        // Adjust iterations to limit typical single runs to <= 10 ms;
        // Notably, fair queues get fewer iters.
        // Unbounded queues can legitimately OOME if iterations
        // high enough, but we have a sufficiently low limit here.
        run(new ArrayBlockingQueue<Integer>(100), i, 300);
        run(new LinkedBlockingQueue<Integer>(100), i, 700);
        run(new LinkedBlockingDeque<Integer>(100), i , 500);
        run(new LinkedTransferQueue<Integer>(), i, 1000);
        run(new PriorityBlockingQueue<Integer>(), i, 1000);
        run(new SynchronousQueue<Integer>(), i, 500);
        run(new SynchronousQueue<Integer>(true), i, 200);
        run(new ArrayBlockingQueue<Integer>(100, true), i, 100);
    }

    pool.shutdown();
    if (! pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS))
        throw new Error();
    pool = null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:MultipleProducersSingleConsumerLoops.java


注:本文中的java.util.concurrent.PriorityBlockingQueue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。