当前位置: 首页>>代码示例>>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;未经允许,请勿转载。