Java Code Examples for java.util.concurrent.LinkedBlockingQueue

The following are top voted examples for showing how to use java.util.concurrent.LinkedBlockingQueue. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ditb   File: IndexResultScanner.java   Source Code and License 6 votes vote down vote up
public IndexResultScanner(List<SingleScanner> scanners, byte[][] resultColumns,
    int resultBufferSize, float loadFactor) {
  this.scanners = scanners;
  this.resultColumns = resultColumns;
  this.resultBufferSize = resultBufferSize;
  this.loadFactor = loadFactor;
  this.minLoadSize = (int) (this.resultBufferSize * this.loadFactor);
  this.resultBuffer = new LinkedBlockingQueue<Result>(resultBufferSize);

  LOG.debug("IndexResultScanner is started!");

  this.scannerNum = this.scanners.size();
  this.finishedScanner = new ArrayList<String>();
  this.stoppedScanner = new ArrayList<String>();

  this.startTime = System.currentTimeMillis();

  int i = 0;
  for (SingleScanner scanner : this.scanners) {
    scanner.setName("Scanner" + i++);
    scanner.setIndexResultScanner(this);
    scanner.start();
  }
  this.restartTimes = 0;
  this.MAX_RESTART_TIMES = HBaseConfiguration.create().getInt("hbase.client.retries.number", 10);
}
 
Example 2
Project: GitHub   File: DiskLruCache.java   Source Code and License 6 votes vote down vote up
/**
 * Create a cache which will reside in {@code directory}. This cache is lazily initialized on
 * first access and will be created if it does not exist.
 *
 * @param directory a writable directory
 * @param valueCount the number of values per cache entry. Must be positive.
 * @param maxSize the maximum number of bytes this cache should use to store
 */
public static DiskLruCache create(FileSystem fileSystem, File directory, int appVersion,
    int valueCount, long maxSize) {
  if (maxSize <= 0) {
    throw new IllegalArgumentException("maxSize <= 0");
  }
  if (valueCount <= 0) {
    throw new IllegalArgumentException("valueCount <= 0");
  }

  // Use a single background thread to evict entries.
  Executor executor = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS,
      new LinkedBlockingQueue<Runnable>(), Util.threadFactory("OkHttp DiskLruCache", true));

  return new DiskLruCache(fileSystem, directory, appVersion, valueCount, maxSize, executor);
}
 
Example 3
Project: htsjdk-s3-plugin   File: ParallelPartsLoaderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void rightBoundsOfProduceTasksTest() throws Exception {
    BlockingQueue<Future<Optional<byte[]>>> tasksQueue = new LinkedBlockingQueue<>();
    S3DataLoaderMocker.mockPrimitiveLoadFromTo(mockFactory, DATA_SIZE);

    new ParallelPartsLoader(
            S3DataLoaderMocker.FAKE_URI,
            0,
            DATA_SIZE,
            mockFactory,
            tasksQueue
    );
    int numberOfFullChunks = 7;
    for (int i = 0; i < numberOfFullChunks; i++) {
        int ruleForIncreaseChunkSize = (i / 2 + 1) < 4 ? i / 2 + 1 : 3;
        checkRightSizeOfChunk(tasksQueue, (int) Math.pow(MIN_PART_SIZE, ruleForIncreaseChunkSize));
    }

    checkRightSizeOfChunk(tasksQueue, 1);
    Assert.assertFalse(tasksQueue.take().get().isPresent());
}
 
Example 4
Project: bireme   File: RowCache.java   Source Code and License 6 votes vote down vote up
/**
 * Create cache for a destination table.
 *
 * @param cxt the bireme context
 * @param tableName the table name to cached
 * @param pipeLine the pipeLine belongs to which
 */
public RowCache(Context cxt, String tableName, PipeLine pipeLine) {
  this.cxt = cxt;
  this.tableName = tableName;
  this.pipeLine = pipeLine;

  this.lastMergeTime = new Date().getTime();
  this.mergeInterval = cxt.conf.merge_interval;
  this.batchSize = cxt.conf.batch_size;

  this.rows = new LinkedBlockingQueue<Row>(cxt.conf.batch_size * 2);
  this.commitCallback = new LinkedBlockingQueue<CommitCallback>();

  this.localMerger = new LinkedList<RowBatchMerger>();
  for (int i = 0; i < cxt.conf.loader_task_queue_size; i++) {
    localMerger.add(new RowBatchMerger());
  }

  this.mergeResult = new LinkedBlockingQueue<Future<LoadTask>>(cxt.conf.loader_task_queue_size);
  this.loader = new ChangeLoader(cxt, pipeLine, tableName, mergeResult);

  // add statistics
  pipeLine.stat.addGaugeForCache(tableName, this);
}
 
Example 5
Project: DUnit   File: DUnitThreadManager.java   Source Code and License 6 votes vote down vote up
private ThreadPoolExecutor createIOPoolExecutor(){
	//IO线程工厂类
	ThreadFactory threadFactory = new ThreadFactory() {
		@Override
		public Thread newThread(@NonNull Runnable runnable) {
			Thread thread = new Thread(runnable);
			thread.setName("dunit-io");
			return thread;
		}
	};

	//创建一个任务拒绝策略
	//直接忽略新进的任务
	RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.DiscardPolicy();
	//创建一个最大线程数为3的线程池
	ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1, 3, 3, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10),threadFactory,rejectedExecutionHandler);
	//当核心线程空闲时,允许杀死核心线程
	poolExecutor.allowCoreThreadTimeOut(true);
	return poolExecutor;
}
 
Example 6
Project: htsjdk-s3-plugin   File: ParallelPartsLoaderTest.java   Source Code and License 6 votes vote down vote up
@Test
public void taskProducerShouldTerminateWhenItIsCanceled() throws InterruptedException {
    BlockingQueue<Future<Optional<byte[]>>> tasksQueue = new LinkedBlockingQueue<>();

    ParallelPartsLoader taskProducer = new ParallelPartsLoader(
            S3DataLoaderMocker.FAKE_URI,
            0,
            DATA_SIZE,
            mockFactory,
            tasksQueue
    );
    CompletableFuture.runAsync(taskProducer)
            .thenAccept(r -> taskProducer.cancelLoading())
            .thenAccept(r -> Assert.assertTrue(tasksQueue.isEmpty()));

}
 
Example 7
Project: diorite-configs-java8   File: YamlCollectionCreator.java   Source Code and License 6 votes vote down vote up
static void putAllCollections(Map<Class<?>, IntFunction<?>> map, Map<Class<?>, Function<?, ?>> unmodMap)
{
    safePut(map, ArrayList.class, ArrayList::new);
    safePut(map, HashSet.class, LinkedHashSet::new);
    safePut(map, Properties.class, x -> new Properties());
    safePut(map, Hashtable.class, Hashtable::new);

    safePut(map, Collection.class, ArrayList::new);
    safePut(map, Set.class, LinkedHashSet::new);
    safePut(map, List.class, ArrayList::new);
    safePut(map, SortedSet.class, x -> new TreeSet<>());
    safePut(map, Queue.class, x -> new ConcurrentLinkedQueue<>());
    safePut(map, Deque.class, x -> new ConcurrentLinkedDeque<>());
    safePut(map, BlockingQueue.class, x -> new LinkedBlockingQueue<>());
    safePut(map, BlockingDeque.class, x -> new LinkedBlockingDeque<>());


    safePut(map, HashMap.class, LinkedHashMap::new);
    safePut(map, LinkedHashMap.class, LinkedHashMap::new);
    safePut(map, ConcurrentHashMap.class, ConcurrentHashMap::new);

    safePut(map, Map.class, LinkedHashMap::new);
    safePut(map, ConcurrentMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, ConcurrentNavigableMap.class, x -> new ConcurrentSkipListMap<>());
    safePut(map, SortedMap.class, i -> new TreeMap<>());
}
 
Example 8
Project: AssistantBySDK   File: NavigatorService.java   Source Code and License 6 votes vote down vote up
/**
 * 检查路书是否堵车
 *
 * @param target     目标地点
 * @param routeModel 路书
 * @param sb         路况信息
 * @return true=是
 */
private boolean setRoadTrafficNotInNavigate(String target, RouteModel routeModel, StringBuilder sb) {
    routeModel.refreshRoadCondition();
    Log.i(TAG, "conditionNodes.size=" + routeModel.getConditionNodes().size());
    Queue<Integer> rQueue = new LinkedBlockingQueue<Integer>();
    int conjestionCount = 0;
    for (int i = 0; i < routeModel.getConditionNodes().size(); ++i) {
        if (routeModel.getConditionNodes().get(i).getRoadCondition() >= RouteModel.ROAD_CONDITION_TYPE_Slow) {
            rQueue.offer(i);
            if (routeModel.getConditionNodes().get(i).getRoadCondition() > RouteModel.ROAD_CONDITION_TYPE_Slow) {
                conjestionCount++;
            }
        }
    }
    return setTrafficState(sb, routeModel, rQueue, conjestionCount, 0);
}
 
Example 9
Project: fresco_floodlight   File: TopologyManager.java   Source Code and License 6 votes vote down vote up
@Override
public void init(FloodlightModuleContext context)
		throws FloodlightModuleException {
	linkDiscoveryService = context.getServiceImpl(ILinkDiscoveryService.class);
	threadPoolService = context.getServiceImpl(IThreadPoolService.class);
	floodlightProviderService = context.getServiceImpl(IFloodlightProviderService.class);
	switchService = context.getServiceImpl(IOFSwitchService.class);
	restApiService = context.getServiceImpl(IRestApiService.class);
	debugCounterService = context.getServiceImpl(IDebugCounterService.class);
	debugEventService = context.getServiceImpl(IDebugEventService.class);

	switchPorts = new HashMap<DatapathId, Set<OFPort>>();
	switchPortLinks = new HashMap<NodePortTuple, Set<Link>>();
	directLinks = new HashMap<NodePortTuple, Set<Link>>();
	portBroadcastDomainLinks = new HashMap<NodePortTuple, Set<Link>>();
	tunnelPorts = new HashSet<NodePortTuple>();
	topologyAware = new ArrayList<ITopologyListener>();
	ldUpdates = new LinkedBlockingQueue<LDUpdate>();
	haListener = new HAListenerDelegate();
	registerTopologyDebugCounters();
	registerTopologyDebugEvents();
}
 
Example 10
Project: JavaCommon   File: BlockingQueueDemo.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) {
	BlockingQueue<Integer> blockingQueue = new LinkedBlockingQueue<Integer>(3);
	Producer producer = new Producer(blockingQueue);
	Consumer consumer = new Consumer(blockingQueue);
	// 创建5个生产者,5个消费者
	for (int i = 0; i < 6; i++) {
		if (i < 5) {
			new Thread(producer, "producer" + i).start();
		} else {
			new Thread(consumer, "consumer" + (i - 5)).start();
		}
	}

	try {
		Thread.sleep(1000);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	producer.shutDown();
	consumer.shutDown();
}
 
Example 11
Project: SmartRefreshLayout   File: RefreshContentWrapper.java   Source Code and License 6 votes vote down vote up
protected View findScrollableViewInternal(View content, boolean selfable) {
    View scrollableView = null;
    Queue<View> views = new LinkedBlockingQueue<>(Collections.singletonList(content));
    while (!views.isEmpty() && scrollableView == null) {
        View view = views.poll();
        if (view != null) {
            if ((selfable || view != content) && isScrollableView(view)) {
                scrollableView = view;
            } else if (view instanceof ViewGroup) {
                ViewGroup group = (ViewGroup) view;
                for (int j = 0; j < group.getChildCount(); j++) {
                    views.add(group.getChildAt(j));
                }
            }
        }
    }
    return scrollableView == null ? content : scrollableView;
}
 
Example 12
Project: alfresco-data-model   File: DictionaryDAOTest.java   Source Code and License 6 votes vote down vote up
private void initDictionaryCaches(DictionaryDAOImpl dictionaryDAO, TenantService tenantService)
{
    CompiledModelsCache compiledModelsCache = new CompiledModelsCache();
    compiledModelsCache.setDictionaryDAO(dictionaryDAO);
    compiledModelsCache.setTenantService(tenantService);
    compiledModelsCache.setRegistry(new DefaultAsynchronouslyRefreshedCacheRegistry());
    TraceableThreadFactory threadFactory = new TraceableThreadFactory();
    threadFactory.setThreadDaemon(true);
    threadFactory.setThreadPriority(Thread.NORM_PRIORITY);

    ThreadPoolExecutor threadPoolExecutor = new DynamicallySizedThreadPoolExecutor(20, 20, 90, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory,
            new ThreadPoolExecutor.CallerRunsPolicy());
    compiledModelsCache.setThreadPoolExecutor(threadPoolExecutor);
    dictionaryDAO.setDictionaryRegistryCache(compiledModelsCache);
    dictionaryDAO.init();
}
 
Example 13
Project: ditb   File: FSHLog.java   Source Code and License 6 votes vote down vote up
/**
 * UPDATE!
 * @param syncs the batch of calls to sync that arrived as this thread was starting; when done,
 * we will put the result of the actual hdfs sync call as the result.
 * @param sequence The sequence number on the ring buffer when this thread was set running.
 * If this actual writer sync completes then all appends up this point have been
 * flushed/synced/pushed to datanodes.  If we fail, then the passed in <code>syncs</code>
 * futures will return the exception to their clients; some of the edits may have made it out
 * to data nodes but we will report all that were part of this session as failed.
 */
SyncRunner(final String name, final int maxHandlersCount) {
  super(name);
  // LinkedBlockingQueue because of
  // http://www.javacodegeeks.com/2010/09/java-best-practices-queue-battle-and.html
  // Could use other blockingqueues here or concurrent queues.
  //
  // We could let the capacity be 'open' but bound it so we get alerted in pathological case
  // where we cannot sync and we have a bunch of threads all backed up waiting on their syncs
  // to come in.  LinkedBlockingQueue actually shrinks when you remove elements so Q should
  // stay neat and tidy in usual case.  Let the max size be three times the maximum handlers.
  // The passed in maxHandlerCount is the user-level handlers which is what we put up most of
  // but HBase has other handlers running too -- opening region handlers which want to write
  // the meta table when succesful (i.e. sync), closing handlers -- etc.  These are usually
  // much fewer in number than the user-space handlers so Q-size should be user handlers plus
  // some space for these other handlers.  Lets multiply by 3 for good-measure.
  this.syncFutures = new LinkedBlockingQueue<SyncFuture>(maxHandlersCount * 3);
}
 
Example 14
Project: PrivacyStreams   File: PStream.java   Source Code and License 6 votes vote down vote up
/**
 * Output the items in the stream with a function.
 * This method will block until the result returns.
 * Eg. `output(StatisticOperators.count())` will output the number of items.
 *
 * @param itemsCollector the function used to output current stream
 * @param <Tout> the type of the result
 * @return the result
 * @throws PSException if failed to the result.
 */
@PSAction(blocking = true)
public <Tout> Tout output(Function<List<Item>, Tout> itemsCollector) throws PSException {
    final BlockingQueue<Object> resultQueue = new LinkedBlockingQueue<>();
    Callback<Tout> resultHandler = new Callback<Tout>() {
        @Override
        protected void onInput(Tout input) {
            resultQueue.add(input);
        }

        @Override
        protected void onFail(PSException exception) {
            resultQueue.add(exception);
        }
    };
    this.output(itemsCollector, resultHandler);
    try {
        Object resultOrException = resultQueue.take();
        if (resultOrException instanceof PSException) {
            throw (PSException) resultOrException;
        }
        return (Tout) resultOrException;
    } catch (InterruptedException e) {
        throw PSException.INTERRUPTED(e.getMessage());
    }
}
 
Example 15
Project: sumo   File: ParallelGeoCoding.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * @param coords
 * @return
 * @throws InterruptedException
 * @throws ExecutionException
 */
public List<double[]> parallelPixelFromGeo(final Coordinate[] coords)
		throws InterruptedException, ExecutionException {
	int processors = Runtime.getRuntime().availableProcessors();
	ThreadPoolExecutor executor = new ThreadPoolExecutor(2, processors, 2, TimeUnit.SECONDS,
			new LinkedBlockingQueue<Runnable>());//(ThreadPoolExecutor)Executors.newFixedThreadPool(processors);
	try {
		final List<Future<double[]>> tasks = new ArrayList<Future<double[]>>();
		for (int i = 0; i < coords.length; i++) {
			tasks.add(executor.submit(new ParallelReverse(coords[i].x, coords[i].y)));
		}
		executor.shutdown();

		final List<double[]> points = new ArrayList<double[]>();
		for (Future<double[]> result : tasks) {
			List<double[]> l = Arrays.asList(result.get());
			points.addAll(l);
		}

		return points;
	} catch (Exception e) {
		if (!executor.isShutdown())
			executor.shutdown();
		throw e;
	}
}
 
Example 16
Project: hadoop   File: AsyncDiskService.java   Source Code and License 6 votes vote down vote up
/**
 * Create a AsyncDiskServices with a set of volumes (specified by their
 * root directories).
 * 
 * The AsyncDiskServices uses one ThreadPool per volume to do the async
 * disk operations.
 * 
 * @param volumes The roots of the file system volumes.
 */
public AsyncDiskService(String[] volumes) {
  
  threadFactory = new ThreadFactory() {
    @Override
    public Thread newThread(Runnable r) {
      return new Thread(threadGroup, r);
    }
  };
  
  // Create one ThreadPool per volume
  for (int v = 0 ; v < volumes.length; v++) {
    ThreadPoolExecutor executor = new ThreadPoolExecutor(
        CORE_THREADS_PER_VOLUME, MAXIMUM_THREADS_PER_VOLUME, 
        THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, 
        new LinkedBlockingQueue<Runnable>(), threadFactory);

    // This can reduce the number of running threads
    executor.allowCoreThreadTimeOut(true);
    executors.put(volumes[v], executor);
  }
  
}
 
Example 17
Project: mycat-src-1.6.1-RELEASE   File: DataMigrator.java   Source Code and License 6 votes vote down vote up
private void migrateData() throws SQLException{
	executor =  new ThreadPoolExecutor(margs.getThreadCount(), margs.getThreadCount(),
               0L, TimeUnit.MILLISECONDS,
               new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.CallerRunsPolicy());
	for(TableMigrateInfo table:migrateTables){
		if(!table.isError()){ //忽略已出错的拆分表
			List<DataNodeMigrateInfo> detailList = table.getDataNodesDetail();
			for(DataNodeMigrateInfo info:detailList){
				executor.execute(new DataMigrateRunner(table, info.getSrc(), info.getTarget(), table.getTableName(), info.getTempFile()));
			}
		}
	}
	executor.shutdown();
	while(true){
		if(executor.isTerminated()){
			break;
		}
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			LOGGER.error("error",e);
		}
	}
}
 
Example 18
Project: boohee_v5.6   File: WebSocketImpl.java   Source Code and License 6 votes vote down vote up
public WebSocketImpl(WebSocketListener listener, Draft draft) {
    this.flushandclosestate = false;
    this.readystate = READYSTATE.NOT_YET_CONNECTED;
    this.draft = null;
    this.current_continuous_frame_opcode = null;
    this.handshakerequest = null;
    this.closemessage = null;
    this.closecode = null;
    this.closedremotely = null;
    if (listener == null || (draft == null && this.role == Role.SERVER)) {
        throw new IllegalArgumentException("parameters must not be null");
    }
    this.outQueue = new LinkedBlockingQueue();
    this.inQueue = new LinkedBlockingQueue();
    this.wsl = listener;
    this.role = Role.CLIENT;
    if (draft != null) {
        this.draft = draft.copyInstance();
    }
}
 
Example 19
Project: sumo   File: ParallelGeoCoding.java   Source Code and License 6 votes vote down vote up
public List<double[]> parallelGeoFromPixel(final Coordinate[] coords)
		throws InterruptedException, ExecutionException {
	int processors = Runtime.getRuntime().availableProcessors();
	ThreadPoolExecutor executor = new ThreadPoolExecutor(2, processors, 5000, TimeUnit.MILLISECONDS,
			new LinkedBlockingQueue<Runnable>());//(ThreadPoolExecutor)Executors.newFixedThreadPool(processors);

	List<Callable<double[]>> tasks = new ArrayList<Callable<double[]>>();
	for (final Coordinate c : coords) {
		tasks.add(new ParallelForward(c.y,c.x));
	}
	List<Future<double[]>> results = executor.invokeAll(tasks);
	executor.shutdown();

	List<double[]> points = new ArrayList<double[]>();
	for (Future<double[]> result : results) {
		List<double[]> l = Arrays.asList(result.get());
		points.addAll(l);
	}

	return points;
}
 
Example 20
Project: YouTube-Thumbnail-View   File: ThumbnailLoader.java   Source Code and License 6 votes vote down vote up
private ThumbnailLoader(@Nullable Context context, @Nullable String googleApiKey) {
   String metaGoogleApiKey = googleApiKey;
   if (context != null) {
      try {
         final ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
         if (appInfo.metaData != null) {
            metaGoogleApiKey = appInfo.metaData.getString("com.codewaves.youtubethumbnailview.ApiKey");
         }
      }
      catch (PackageManager.NameNotFoundException e) {
         // Ignore
      }
   }

   final BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
   executor = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE, 0L, TimeUnit.MILLISECONDS, taskQueue);

   requestMap = new WeakHashMap<>();
   defaultInfoDownloader = new ApiVideoInfoDownloader(metaGoogleApiKey);
   defaultImageLoader = new SimpleImageLoader();
}
 
Example 21
Project: athena   File: BoundedThreadPool.java   Source Code and License 5 votes vote down vote up
private BoundedThreadPool(int numberOfThreads,
                          ThreadFactory threadFactory) {
    super(numberOfThreads, numberOfThreads,
          0L, TimeUnit.MILLISECONDS,
          new LinkedBlockingQueue<>(maxQueueSize),
          threadFactory,
          new CallerFeedbackPolicy());
    underHighLoad = ((CallerFeedbackPolicy) getRejectedExecutionHandler()).load();
}
 
Example 22
Project: dubbox-hystrix   File: SimpleMonitorService.java   Source Code and License 5 votes vote down vote up
public SimpleMonitorService() {
    queue = new LinkedBlockingQueue<URL>(Integer.parseInt(ConfigUtils.getProperty("dubbo.monitor.queue", "100000")));
    writeThread = new Thread(new Runnable() {
        public void run() {
            while (running) {
                try {
                    write(); // 记录统计日志
                } catch (Throwable t) { // 防御性容错
                    logger.error("Unexpected error occur at write stat log, cause: " + t.getMessage(), t);
                    try {
                        Thread.sleep(5000); // 失败延迟
                    } catch (Throwable t2) {
                    }
                }
            }
        }
    });
    writeThread.setDaemon(true);
    writeThread.setName("DubboMonitorAsyncWriteLogThread");
    writeThread.start();
    chartFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
        public void run() {
            try {
                draw(); // 绘制图表
            } catch (Throwable t) { // 防御性容错
                logger.error("Unexpected error occur at draw stat chart, cause: " + t.getMessage(), t);
            }
        }
    }, 1, 300, TimeUnit.SECONDS);
    INSTANCE = this;
}
 
Example 23
Project: happylifeplat-transaction   File: TxCompensationServiceImpl.java   Source Code and License 5 votes vote down vote up
public void initCompensatePool() {
    synchronized (LOGGER) {
        QUEUE = new LinkedBlockingQueue<>(txConfig.getCompensationQueueMax());
        final int compensationThreadMax = txConfig.getCompensationThreadMax();
        final TransactionThreadPool threadPool = SpringBeanUtils.getInstance().getBean(TransactionThreadPool.class);
        final ExecutorService executorService = threadPool.newCustomFixedThreadPool(compensationThreadMax);
        LogUtil.info(LOGGER, "启动补偿操作线程数量为:{}", () -> compensationThreadMax);
        for (int i = 0; i < compensationThreadMax; i++) {
            executorService.execute(new Worker());
        }

    }
}
 
Example 24
Project: bubichain-sdk-java   File: BlockChainAdapter.java   Source Code and License 5 votes vote down vote up
public BlockChainManager(Integer index, String uri_address){
    index_ = index;
    draft_ = new Draft_17();
    uri_ = URI.create(uri_address);
    send_queue_ = new LinkedBlockingQueue<>();
    blockchain_manager_thhead = new Thread(this);
    blockchain_manager_thhead.start();
}
 
Example 25
Project: dubbo2   File: ConnectionOrderedChannelHandler.java   Source Code and License 5 votes vote down vote up
public ConnectionOrderedChannelHandler(ChannelHandler handler, URL url) {
    super(handler, url);
    String threadName = url.getParameter(Constants.THREAD_NAME_KEY,Constants.DEFAULT_THREAD_NAME);
    connectionExecutor = new ThreadPoolExecutor(1, 1,
                                 0L, TimeUnit.MILLISECONDS,
                                 new LinkedBlockingQueue<Runnable>(url.getPositiveParameter(Constants.CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)),
                                 new NamedThreadFactory(threadName, true),
                                 new AbortPolicyWithReport(threadName, url)
        );  // FIXME 没有地方释放connectionExecutor!
    queuewarninglimit = url.getParameter(Constants.CONNECT_QUEUE_WARNING_SIZE, Constants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE);
}
 
Example 26
Project: Linux-notifier-Android   File: NetworkCommunicator.java   Source Code and License 5 votes vote down vote up
private NetworkCommunicator()
{
    this.hosts = new LinkedBlockingQueue<>();
    this.ports = new LinkedBlockingQueue<>();
    this.messages = new LinkedBlockingQueue<>();
    this.receivedMessages = new LinkedBlockingQueue<>();
    this.needsResponse = new LinkedBlockingQueue<>();
    this.interval = 200;
}
 
Example 27
Project: AssistantBySDK   File: MobileCommProcessor.java   Source Code and License 5 votes vote down vote up
public MobileCommProcessor(Context mContext, SystemVoiceMediator mediator, Handler handler) {
    super(mContext, mediator);
    this.mHandler = handler;
    mAppConfig = (AppConfig) ((Service) mContext).getApplication();
    tPools = new ThreadPoolExecutor(10, 20, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
    phoneCallListener();
    // 注册收件箱内容观察者
    mContext.getContentResolver().registerContentObserver(Uri.parse(PhoneContactUtils.SMS_URI_INBOX),
            true, new SmsObserver(handler));
    // 注册联系人内容观察者
    mContext.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
            true, new ContactObserver(handler));
}
 
Example 28
Project: tomcat7   File: ContainerBase.java   Source Code and License 5 votes vote down vote up
@Override
protected void initInternal() throws LifecycleException {
    BlockingQueue<Runnable> startStopQueue =
        new LinkedBlockingQueue<Runnable>();
    startStopExecutor = new ThreadPoolExecutor(
            getStartStopThreadsInternal(),
            getStartStopThreadsInternal(), 10, TimeUnit.SECONDS,
            startStopQueue,
            new StartStopThreadFactory(getName() + "-startStop-"));
    startStopExecutor.allowCoreThreadTimeOut(true);
    super.initInternal();
}
 
Example 29
Project: openjdk-jdk10   File: Interrupt.java   Source Code and License 5 votes vote down vote up
private static void realMain(final String[] args) throws Throwable {
    testQueue(new SynchronousQueue<Object>());
    testQueue(new ArrayBlockingQueue<Object>(1,false));
    testQueue(new ArrayBlockingQueue<Object>(1,true));
    testQueue(new LinkedBlockingQueue<Object>(1));
    testQueue(new LinkedBlockingDeque<Object>(1));
}
 
Example 30
Project: Equella   File: AbstractTaskServiceImpl.java   Source Code and License 5 votes vote down vote up
protected ThreadPoolExecutor createPriorityTaskExecutor()
{
	final ThreadPoolExecutor priorityTpe = new ThreadPoolExecutor(12, 12, 60L, TimeUnit.SECONDS,
		new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("TaskRunner.priorityPool"));
	priorityTpe.allowCoreThreadTimeOut(true);
	return priorityTpe;
}
 
Example 31
Project: jaer   File: Network.java   Source Code and License 5 votes vote down vote up
final void implementQueues()
{
    inputBuffer = new LinkedBlockingQueue();
    internalBuffer= new PriorityQueue();
    outputQueue=new MultiReaderQueue();
    
}
 
Example 32
Project: slardar   File: DBCPool.java   Source Code and License 5 votes vote down vote up
public DBCPool(PoolConfig config){
    maxPoolSize = config.getMaxActive();
    minIdle = config.getMinIdle();
    maxIdle = config.getMaxIdle();
    keepAliveTime = config.getMaxWait();
    conpool = new ConcurrentLinkedQueue<Connection>();
    idleQueue = new LinkedBlockingQueue<Connection>();
    initQueue();
}
 
Example 33
Project: GitHub   File: ConstrainedExecutorService.java   Source Code and License 5 votes vote down vote up
/**
 * Factory method to create a new {@code ConstrainedExecutorService} with an unbounded
 * {@link LinkedBlockingQueue} queue.
 * @param name Friendly name to identify the executor in logging and reporting.
 * @param maxConcurrency Maximum number of tasks to execute in parallel on the delegate executor.
 * @param queueSize Number of items that can be queued before new submissions are rejected.
 * @param executor Delegate executor for actually running tasks.
 * @return new {@code ConstrainedExecutorService} instance.
 */
public static ConstrainedExecutorService newConstrainedExecutor(
    String name,
    int maxConcurrency,
    int queueSize,
    Executor executor) {
  return new ConstrainedExecutorService(
      name,
      maxConcurrency,
      executor,
      new LinkedBlockingQueue<Runnable>(queueSize));
}
 
Example 34
Project: rmq4note   File: DefaultMQProducerImpl.java   Source Code and License 5 votes vote down vote up
public void initTransactionEnv() {
    TransactionMQProducer producer = (TransactionMQProducer) this.defaultMQProducer;
    this.checkRequestQueue = new LinkedBlockingQueue<Runnable>(producer.getCheckRequestHoldMax());
    this.checkExecutor = new ThreadPoolExecutor(//
        producer.getCheckThreadPoolMinSize(), //
        producer.getCheckThreadPoolMaxSize(), //
        1000 * 60, //
        TimeUnit.MILLISECONDS, //
        this.checkRequestQueue);
}
 
Example 35
Project: Hitalk   File: AndroidExecutors.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available
 * or create new threads until the core pool is full. tasks will then be queued. If an
 * task cannot be queued, a new thread will be created unless this would exceed max pool
 * size, then the task will be rejected. Threads will time out after 1 second.
 *
 * Core thread timeout is only available on android-9+.
 *
 * @param threadFactory the factory to use when creating new threads
 * @return the newly created thread pool
 */
public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
  ThreadPoolExecutor executor =  new ThreadPoolExecutor(
          CORE_POOL_SIZE,
          MAX_POOL_SIZE,
          KEEP_ALIVE_TIME, TimeUnit.SECONDS,
          new LinkedBlockingQueue<Runnable>(),
          threadFactory);

  allowCoreThreadTimeout(executor, true);

  return executor;
}
 
Example 36
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   Source Code and License 5 votes vote down vote up
/**
 * poll succeeds unless empty
 */
public void testPoll() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.poll());
    }
    assertNull(q.poll());
}
 
Example 37
Project: message-broker   File: QueueHandler.java   Source Code and License 5 votes vote down vote up
DbBackedQueueImpl(String queueName, boolean autoDelete,
                  SharedMessageStore sharedMessageStore) throws BrokerException {
    super(queueName, true, autoDelete);
    this.sharedMessageStore = sharedMessageStore;
    this.memQueue = new LinkedBlockingQueue<>();
    Collection<Message> messages = sharedMessageStore.readStoredMessages(queueName);
    memQueue.addAll(messages);
}
 
Example 38
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   Source Code and License 5 votes vote down vote up
/**
 * take retrieves elements in FIFO order
 */
public void testTake() throws InterruptedException {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.take());
    }
}
 
Example 39
Project: IO   File: ProcessorManager.java   Source Code and License 5 votes vote down vote up
private ProcessorManager(IMediaReader toProcess, AdvancedOptions options, String baseFileName, IProcessor... processors) {
    this.toProcess = toProcess;
    this.processors = new ArrayList<>(); // TODO: Thread safe list here instead?
    this.processors.addAll(Arrays.asList(processors));
    this.queue = new LinkedBlockingQueue<>();
    this.status = new SimpleLongProperty(0l);
    this.options = options;
    this.baseFileName = baseFileName;
}
 
Example 40
Project: dble   File: MultiNodeMergeHandler.java   Source Code and License 5 votes vote down vote up
public void execute() throws Exception {
    synchronized (exeHandlers) {
        if (terminate.get())
            return;
        for (BaseSelectHandler exeHandler : exeHandlers) {
            MySQLConnection exeConn = exeHandler.initConnection();
            if (exeConn != null) {
                exeConn.setComplexQuery(true);
                queues.put(exeConn, new LinkedBlockingQueue<HeapItem>(queueSize));
                exeHandler.execute(exeConn);
            }
        }
    }
}
 
Example 41
Project: Nird2   File: SimplexOutgoingSession.java   Source Code and License 5 votes vote down vote up
SimplexOutgoingSession(DatabaseComponent db, Executor dbExecutor,
		EventBus eventBus, ContactId contactId,
		int maxLatency, RecordWriter recordWriter) {
	this.db = db;
	this.dbExecutor = dbExecutor;
	this.eventBus = eventBus;
	this.contactId = contactId;
	this.maxLatency = maxLatency;
	this.recordWriter = recordWriter;
	outstandingQueries = new AtomicInteger(2); // One per type of record
	writerTasks = new LinkedBlockingQueue<ThrowingRunnable<IOException>>();
}
 
Example 42
Project: take   File: TakeTest.java   Source Code and License 5 votes vote down vote up
@Test
public void test06() throws Exception {
    BlockingQueue<String> queue = new LinkedBlockingQueue<>();
    queue.add("1");
    queue.add("2");
    queue.add("3");

    System.out.println(queue.poll());
    queue.add("4");
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
    System.out.println(queue.poll());
}
 
Example 43
Project: Responder-Android   File: WebSocketImpl.java   Source Code and License 5 votes vote down vote up
/**
 * crates a websocket with client role
 * 
 * @param socket
 *            may be unbound
 */
public WebSocketImpl( WebSocketListener listener , Draft draft ) {
	if( listener == null || ( draft == null && role == Role.SERVER ) )// socket can be null because we want do be able to create the object without already having a bound channel
		throw new IllegalArgumentException( "parameters must not be null" );
	this.outQueue = new LinkedBlockingQueue<ByteBuffer>();
	inQueue = new LinkedBlockingQueue<ByteBuffer>();
	this.wsl = listener;
	this.role = Role.CLIENT;
	if( draft != null )
		this.draft = draft.copyInstance();
}
 
Example 44
Project: ditb   File: HTableMultiplexer.java   Source Code and License 5 votes vote down vote up
public FlushWorker(Configuration conf, ClusterConnection conn, HRegionLocation addr,
    HTableMultiplexer htableMultiplexer, int perRegionServerBufferQueueSize,
    ExecutorService pool, ScheduledExecutorService executor) {
  this.addr = addr;
  this.multiplexer = htableMultiplexer;
  this.queue = new LinkedBlockingQueue<>(perRegionServerBufferQueueSize);
  RpcRetryingCallerFactory rpcCallerFactory = RpcRetryingCallerFactory.instantiate(conf);
  RpcControllerFactory rpcControllerFactory = RpcControllerFactory.instantiate(conf);
  this.ap = new AsyncProcess(conn, conf, pool, rpcCallerFactory, false, rpcControllerFactory);
  this.executor = executor;
  this.maxRetryInQueue = conf.getInt(TABLE_MULTIPLEXER_MAX_RETRIES_IN_QUEUE, 10000);
}
 
Example 45
Project: dble   File: NIOConnector.java   Source Code and License 5 votes vote down vote up
public NIOConnector(String name, NIOReactorPool reactorPool)
        throws IOException {
    super.setName(name);
    this.name = name;
    this.selector = Selector.open();
    this.reactorPool = reactorPool;
    this.connectQueue = new LinkedBlockingQueue<>();
}
 
Example 46
Project: kmanager   File: SystemManager.java   Source Code and License 5 votes vote down vote up
private static void initAlert(AppConfig config) {
  EmailSender.setConfig(config);
  TaskManager.init(config);
  if (offsetInfoCacheQueue != null) {
    offsetInfoCacheQueue.clear();
  } else {
    offsetInfoCacheQueue = new LinkedBlockingQueue<KafkaInfo>(config.getOffsetInfoCacheQueue());
  }
  if (worker != null)
    worker.shutdownNow();
  int corePoolSize = config.getOffsetInfoHandler() != null ? config.getOffsetInfoHandler() : DEFAULT_THREAD_POOL_SIZE;
  if (worker != null) {
    worker.shutdownNow();
  }
  worker = Executors.newFixedThreadPool(corePoolSize, new WorkerThreadFactory("AlertTaskChecker"));

  for (int i = 0; i < corePoolSize; i++) {
    worker.submit(new TaskHandler());
  }

  File dir = new File(config.getTaskFolder());
  if (!dir.exists()) {
    dir.mkdir();
  }
  // Scan task folder load tasks to memory
  File[] listOfFiles = dir.listFiles();
  for (File file : listOfFiles) {
    if (file.isFile() && (file.getName().substring(file.getName().lastIndexOf('.') + 1).equals("task"))) {
      String strTaskContent = CommonUtils.loadFileContent(file.getAbsolutePath());
      TaskManager.addTask(new Gson().fromJson(strTaskContent, TaskContent.class));
    }
  }
}
 
Example 47
Project: cas-server-4.2.1   File: SimpleHttpClientFactoryBean.java   Source Code and License 5 votes vote down vote up
/**
 * Build a {@link FutureRequestExecutionService} from the current properties and a HTTP client.
 *
 * @param httpClient the provided HTTP client
 * @return the built request executor service
 */
private FutureRequestExecutionService buildRequestExecutorService(final CloseableHttpClient httpClient) {
    if (this.executorService == null) {
        this.executorService = new ThreadPoolExecutor(this.threadsNumber, this.threadsNumber,
                0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(this.queueSize));
    }

    return new FutureRequestExecutionService(httpClient, this.executorService);
}
 
Example 48
Project: dubbox-hystrix   File: CachedThreadPool.java   Source Code and License 5 votes vote down vote up
public Executor getExecutor(URL url) {
    String name = url.getParameter(Constants.THREAD_NAME_KEY, Constants.DEFAULT_THREAD_NAME);
    int cores = url.getParameter(Constants.CORE_THREADS_KEY, Constants.DEFAULT_CORE_THREADS);
    int threads = url.getParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);
    int queues = url.getParameter(Constants.QUEUES_KEY, Constants.DEFAULT_QUEUES);
    int alive = url.getParameter(Constants.ALIVE_KEY, Constants.DEFAULT_ALIVE);
    return new ThreadPoolExecutor(cores, threads, alive, TimeUnit.MILLISECONDS, 
    		queues == 0 ? new SynchronousQueue<Runnable>() : 
    			(queues < 0 ? new LinkedBlockingQueue<Runnable>() 
    					: new LinkedBlockingQueue<Runnable>(queues)),
    		new NamedThreadFactory(name, true), new AbortPolicyWithReport(name, url));
}
 
Example 49
Project: VBrowser-Android   File: DownloadManager.java   Source Code and License 5 votes vote down vote up
private void parseM3u8(String m3u8Url, String newM3u8FileName, String outputPath, LinkedBlockingQueue<Map<String, String>> sizeDetectQueue, LinkedBlockingQueue<Map<String, String>> downloadQueue) throws IOException {
    String m3U8Content = HttpRequestUtil.getResponseString(HttpRequestUtil.sendGetRequest(m3u8Url));
    String newM3u8FileContent = "";
    boolean subFile = false;
    for(String lineStr:m3U8Content.split("\n")){
        if(lineStr.startsWith("#")){
            newM3u8FileContent = newM3u8FileContent+lineStr+"\n";
            if(lineStr.startsWith("#EXT-X-STREAM-INF")){
                subFile = true;
            }
        }else{
            String uuidStr = UUIDUtil.genUUID();
            String fileUrl = new URL(new URL(m3u8Url), lineStr.trim()).toString();
            if(subFile){
                subFile = false;
                parseM3u8(fileUrl, uuidStr+".m3u8", outputPath,sizeDetectQueue, downloadQueue);
                newM3u8FileContent = newM3u8FileContent+"/"+uuidStr + ".m3u8\n";
            }else{
                String videoFilePath = outputPath + File.separator + uuidStr + ".ts";
                HashMap<String, String> hashMap = new HashMap<String, String>();
                hashMap.put("url", fileUrl);
                hashMap.put("downloadPath", videoFilePath);
                sizeDetectQueue.add(hashMap);
                downloadQueue.add(hashMap);
                newM3u8FileContent = newM3u8FileContent+"/"+ uuidStr + ".ts\n";
            }
        }
    }
    FileUtil.stringToFile(newM3u8FileContent, outputPath+File.separator+newM3u8FileName);
}
 
Example 50
Project: Proyecto-DASI   File: CopyOfProcesadorItems.java   Source Code and License 5 votes vote down vote up
public CopyOfProcesadorItems(AgenteCognitivo agente) {
	this.agente = agente;

	this.infoExtractedQ = new LinkedBlockingQueue<ExtractedInfo>(
			CAPACIDAD_BUZON_CONT_MESSG);
	this.itfProcesadorInfoExtracted = agente.getControl();
	this.envioEvidencias = new EnvioInfoExtractedThread();		
}
 
Example 51
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   Source Code and License 5 votes vote down vote up
/**
 * Queue transitions from empty to full when elements added
 */
public void testEmptyFull() {
    LinkedBlockingQueue q = new LinkedBlockingQueue(2);
    assertTrue(q.isEmpty());
    assertEquals("should have room for 2", 2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
 
Example 52
Project: miracle-remote   File: NettyClientDispatchHandler.java   Source Code and License 5 votes vote down vote up
public Response getResponse(final long messageId) {
    Response result;
    responseMap.putIfAbsent(messageId, new LinkedBlockingQueue<Response>(1));
    try {
        result = responseMap.get(messageId).take();
        if (null == result) {
            result = getSystemMessage();
        }
    } catch (final InterruptedException ex) {
        throw new ClientException(ex);
    } finally {
        responseMap.remove(messageId);
    }
    return result;
}
 
Example 53
Project: netto_rpc   File: AsynchronousChannelHandler.java   Source Code and License 5 votes vote down vote up
public AsynchronousChannelHandler(ServerDesc serverDesc, Map<String, NettoServiceBean> serviceBeans,
		List<InvokeMethodFilter> filters, int maxQueueSize, int numHandlerWorker) {
	super(serverDesc, serviceBeans, filters);

	executor = new ThreadPoolExecutor(numHandlerWorker, numHandlerWorker, 60000L, TimeUnit.SECONDS,
			new LinkedBlockingQueue<Runnable>(maxQueueSize), new NamedThreadFactory("NettoHandlerThread", true));

}
 
Example 54
Project: dubbox-hystrix   File: ConnectionOrderedChannelHandler.java   Source Code and License 5 votes vote down vote up
public ConnectionOrderedChannelHandler(ChannelHandler handler, URL url) {
    super(handler, url);
    String threadName = url.getParameter(Constants.THREAD_NAME_KEY,Constants.DEFAULT_THREAD_NAME);
    connectionExecutor = new ThreadPoolExecutor(1, 1,
                                 0L, TimeUnit.MILLISECONDS,
                                 new LinkedBlockingQueue<Runnable>(url.getPositiveParameter(Constants.CONNECT_QUEUE_CAPACITY, Integer.MAX_VALUE)),
                                 new NamedThreadFactory(threadName, true),
                                 new AbortPolicyWithReport(threadName, url)
        );  // FIXME 没有地方释放connectionExecutor!
    queuewarninglimit = url.getParameter(Constants.CONNECT_QUEUE_WARNING_SIZE, Constants.DEFAULT_CONNECT_QUEUE_WARNING_SIZE);
}
 
Example 55
Project: Pogamut3   File: Test10_SyncAccessToInt.java   Source Code and License 5 votes vote down vote up
@Test
public void test() {
	
	int threads = 40;
	
	ThreadPoolExecutor executor = new ThreadPoolExecutor(threads, threads, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
	
	try {
		int jobs = 1000;
		int add = 1000;
		
		latch = new CountDownLatch(jobs);
		
		for (int i = 0; i < jobs; ++i) {
			executor.execute(new IncReadDecValueAsync(add));
		}
		
		try {
			latch.await();
		} catch (InterruptedException e) {
			throw new RuntimeException("Interrupted.", e);
		}
		
		log.info("Checking value, expecting 0 ...");
		
		if (value != 0) {
			testFailed("value == " + value + " != 0");
		}
		
		testOk();
	} finally {
		executor.shutdownNow();
	}
}
 
Example 56
Project: L2J-Global   File: ThreadPoolManager.java   Source Code and License 5 votes vote down vote up
protected ThreadPoolManager()
{
	_effectsScheduledThreadPool = new ScheduledThreadPoolExecutor(Config.THREAD_P_EFFECTS, new PriorityThreadFactory("EffectsSTPool", Thread.NORM_PRIORITY));
	_generalScheduledThreadPool = new ScheduledThreadPoolExecutor(Config.THREAD_P_GENERAL, new PriorityThreadFactory("GeneralSTPool", Thread.NORM_PRIORITY));
	_eventScheduledThreadPool = new ScheduledThreadPoolExecutor(Config.THREAD_E_EVENTS, new PriorityThreadFactory("EventSTPool", Thread.NORM_PRIORITY));
	_ioPacketsThreadPool = new ThreadPoolExecutor(Config.IO_PACKET_THREAD_CORE_SIZE, Integer.MAX_VALUE, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new PriorityThreadFactory("I/O Packet Pool", Thread.NORM_PRIORITY + 1));
	_generalPacketsThreadPool = new ThreadPoolExecutor(Config.GENERAL_PACKET_THREAD_CORE_SIZE, Config.GENERAL_PACKET_THREAD_CORE_SIZE + 2, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new PriorityThreadFactory("Normal Packet Pool", Thread.NORM_PRIORITY + 1));
	_generalThreadPool = new ThreadPoolExecutor(Config.GENERAL_THREAD_CORE_SIZE, Config.GENERAL_THREAD_CORE_SIZE + 2, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new PriorityThreadFactory("General Pool", Thread.NORM_PRIORITY));
	_aiScheduledThreadPool = new ScheduledThreadPoolExecutor(Config.AI_MAX_THREAD, new PriorityThreadFactory("AISTPool", Thread.NORM_PRIORITY));
	_eventThreadPool = new ThreadPoolExecutor(Config.EVENT_MAX_THREAD, Config.EVENT_MAX_THREAD + 2, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new PriorityThreadFactory("Event Pool", Thread.NORM_PRIORITY));
	
	scheduleGeneralAtFixedRate(new PurgeTask(), 10, 5, TimeUnit.MINUTES);
}
 
Example 57
Project: bubichain-sdk-java   File: BlockChainAdapter.java   Source Code and License 5 votes vote down vote up
public BlockChainManager(Integer index, String uri_address) {
	index_ = index;
	draft_ = new Draft_17();
	uri_ = URI.create(uri_address);
	send_queue_ = new LinkedBlockingQueue<WsMessage>();
	blockchain_manager_thhead = new Thread(this);
	blockchain_manager_thhead.start();
}
 
Example 58
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   Source Code and License 5 votes vote down vote up
/**
 * Queue contains all elements, in traversal order, of successful addAll
 */
public void testAddAll5() {
    Integer[] empty = new Integer[0];
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i)
        ints[i] = new Integer(i);
    LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
    assertFalse(q.addAll(Arrays.asList(empty)));
    assertTrue(q.addAll(Arrays.asList(ints)));
    for (int i = 0; i < SIZE; ++i)
        assertEquals(ints[i], q.poll());
}
 
Example 59
Project: openjdk-jdk10   File: OfferRemoveLoops.java   Source Code and License 5 votes vote down vote up
void test(String[] args) throws Throwable {
    testQueue(new LinkedBlockingQueue(10));
    testQueue(new LinkedBlockingQueue());
    testQueue(new LinkedBlockingDeque(10));
    testQueue(new LinkedBlockingDeque());
    testQueue(new ArrayBlockingQueue(10));
    testQueue(new PriorityBlockingQueue(10));
    testQueue(new ConcurrentLinkedDeque());
    testQueue(new ConcurrentLinkedQueue());
    testQueue(new LinkedTransferQueue());
}
 
Example 60
Project: upgradeToy   File: CollectionTest.java   Source Code and License 5 votes vote down vote up
@Test
    public void test_queue_copy() {
        LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>();
        queue.add("abc");
        LinkedBlockingQueue<String> queueMileage = new LinkedBlockingQueue<String>(queue);
//        String trucknum = queueMileage.poll();
        queueMileage.remove();
//        System.out.println(trucknum);
        System.out.println(queue);
    }