当前位置: 首页>>代码示例>>Java>>正文


Java ArrayBlockingQueue.offer方法代码示例

本文整理汇总了Java中java.util.concurrent.ArrayBlockingQueue.offer方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayBlockingQueue.offer方法的具体用法?Java ArrayBlockingQueue.offer怎么用?Java ArrayBlockingQueue.offer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ArrayBlockingQueue的用法示例。


在下文中一共展示了ArrayBlockingQueue.offer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public void test() throws Exception{
	
	Vector<Object> vector = new Vector<Object>();
	ArrayBlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(50000);

	Random myRandom = new Random();
	for (int j = 0; j<50000; j++){
		if (myRandom.nextInt(2) == 0){
			vector.add(i);
			queue.offer(i);
		}
		else{
			vector.add(k);
			queue.offer(k);
		}
	}
	
	assertTrue(Arrays.equals(vector.toArray(), queue.toArray()));
	
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:21,代码来源:TestArrays.java

示例2: passMessageDownstream

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public boolean passMessageDownstream(Object object, MPIMessage currentMessage) {
  int src = router.mainTaskOfExecutor(instancePlan.getThisExecutor(), MPIContext.DEFAULT_PATH);
  RoutingParameters routingParameters = sendRoutingParameters(src, MPIContext.DEFAULT_PATH);
  ArrayBlockingQueue<Pair<Object, MPISendMessage>> pendingSendMessages =
      pendingSendMessagesPerSource.get(src);

  MPIMessage mpiMessage = new MPIMessage(src, type, MPIMessageDirection.OUT, delegete);

  // create a send message to keep track of the serialization
  // at the intial stage the sub-edge is 0
  int di = -1;
  if (routingParameters.getExternalRoutes().size() > 0) {
    di = routingParameters.getDestinationId();
  }
  MPISendMessage sendMessage = new MPISendMessage(src, mpiMessage, edge,
      di, MPIContext.DEFAULT_PATH, currentMessage.getHeader().getFlags(),
      routingParameters.getInternalRoutes(),
      routingParameters.getExternalRoutes());

  // now try to put this into pending
  return pendingSendMessages.offer(
      new ImmutablePair<Object, MPISendMessage>(object, sendMessage));
}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:24,代码来源:MPIDataFlowBroadcast.java

示例3: release

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Channel使用完毕之后,回收到阻塞队列arrayBlockingQueue
 *
 * @param arrayBlockingQueue
 * @param channel
 * @param inetSocketAddress
 */
public void release(ArrayBlockingQueue<Channel> arrayBlockingQueue, Channel channel, InetSocketAddress inetSocketAddress) {
    if (arrayBlockingQueue == null) {
        return;
    }

    //回收之前先检查channel是否可用,不可用的话,重新注册一个,放入阻塞队列
    if (channel == null || !channel.isActive() || !channel.isOpen() || !channel.isWritable()) {
        if (channel != null) {
            channel.deregister().syncUninterruptibly().awaitUninterruptibly();
            channel.closeFuture().syncUninterruptibly().awaitUninterruptibly();
        }
        Channel newChannel = null;
        while (newChannel == null) {
            logger.debug("---------register new Channel-------------");
            newChannel = registerChannel(inetSocketAddress);
        }
        arrayBlockingQueue.offer(newChannel);
        return;
    }
    arrayBlockingQueue.offer(channel);
}
 
开发者ID:linuer,项目名称:nan,代码行数:29,代码来源:NettyChannelPoolFactory.java

示例4: levelOrderTraversal

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public void levelOrderTraversal(Node node) {
	if (node == null) {
		return;
	}
	ArrayBlockingQueue<Node> queue = new ArrayBlockingQueue<>(10);
	
	queue.offer(node);
	
	while(!queue.isEmpty()) {
		Node temp = queue.poll();
		System.out.println(temp.getKey());
		if (temp.leftNode != null) {
			queue.offer(temp.leftNode);
		}
		if(temp.rightNode != null) {
			queue.offer(temp.rightNode);
		}
	}
}
 
开发者ID:arunan123,项目名称:algorithm-implementation-in-java-javascript-scala,代码行数:20,代码来源:BinarySearchTreeMap.java

示例5: sendMessagePartial

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public boolean sendMessagePartial(int source, Object object, int path,
                                    int flags, RoutingParameters routingParameters) {
    lock.lock();
    try {
//      LOG.info(String.format("%d send message partial %d", executor, source));
      // for partial sends we use minus value to find the correct queue
      ArrayBlockingQueue<Pair<Object, MPISendMessage>> pendingSendMessages =
          pendingSendMessagesPerSource.get(source * -1 - 1);

      MPIMessage mpiMessage = new MPIMessage(source, type, MPIMessageDirection.OUT, this);
      int di = -1;
      if (routingParameters.getExternalRoutes().size() > 0) {
        di = routingParameters.getDestinationId();
      }
      // create a send message to keep track of the serialization
      // at the intial stage the sub-edge is 0
      MPISendMessage sendMessage = new MPISendMessage(source, mpiMessage, edge,
          di, path, flags, routingParameters.getInternalRoutes(),
          routingParameters.getExternalRoutes());

      // now try to put this into pending
      boolean ret = pendingSendMessages.offer(
          new ImmutablePair<Object, MPISendMessage>(object, sendMessage));
      return ret;
    } finally {
      lock.unlock();
    }
  }
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:29,代码来源:MPIDataFlowOperation.java

示例6: findMaxKeyBinaryTree

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
private K findMaxKeyBinaryTree(Node node) {
	
	if (node == null)
		return null;
	
	K max = (K)node.key;
	
	ArrayBlockingQueue<Node> queue = new ArrayBlockingQueue<>(20);
	queue.offer(node);
	
	while (!queue.isEmpty()) {
		Node temp = queue.poll();
		
		if(max.compareTo((K)temp.key) > 0) {
			max = max;
		} else {
			max = (K) temp.key;
		}
		
		if (temp.leftNode != null) {
			queue.offer(temp.leftNode);
		}
		if (temp.rightNode != null) {
			queue.offer(temp.rightNode);
		}
	}
	
	return max;
}
 
开发者ID:arunan123,项目名称:algorithm-implementation-in-java-javascript-scala,代码行数:30,代码来源:BinaryTree.java


注:本文中的java.util.concurrent.ArrayBlockingQueue.offer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。