List of usage examples for java.util.concurrent SynchronousQueue SynchronousQueue
public SynchronousQueue()
From source file:zlyh.dmitry.recaller.services.RecordService.java
@Override public void onCreate() { super.onCreate(); nosizequeue = new SynchronousQueue<>(); executor = new ThreadPoolExecutor(1, 1, 1, TimeUnit.MINUTES, nosizequeue); }
From source file:org.apache.hadoop.hbase.master.MasterMobCompactionThread.java
public MasterMobCompactionThread(HMaster master) { this.master = master; this.conf = master.getConfiguration(); final String n = Thread.currentThread().getName(); // this pool is used to run the mob compaction this.masterMobPool = new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() { @Override/*from w w w. j a va 2s . c o m*/ public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-MasterMobCompaction-" + EnvironmentEdgeManager.currentTime()); return t; } }); ((ThreadPoolExecutor) this.masterMobPool).allowCoreThreadTimeOut(true); // this pool is used in the mob compaction to compact the mob files by partitions // in parallel this.mobCompactorPool = MobUtils.createMobCompactorThreadPool(master.getConfiguration()); }
From source file:org.apache.hadoop.hbase.master.MasterMobFileCompactionThread.java
public MasterMobFileCompactionThread(HMaster master) { this.master = master; this.conf = master.getConfiguration(); final String n = Thread.currentThread().getName(); // this pool is used to run the mob file compaction this.masterMobPool = new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new ThreadFactory() { @Override/*from w w w .j av a 2s .c om*/ public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-MasterMobFileCompaction-" + EnvironmentEdgeManager.currentTime()); return t; } }); ((ThreadPoolExecutor) this.masterMobPool).allowCoreThreadTimeOut(true); // this pool is used in the mob file compaction to compact the mob files by partitions // in parallel this.mobFileCompactorPool = MobUtils.createMobFileCompactorThreadPool(master.getConfiguration()); }
From source file:kr.co.bitnine.octopus.frame.SessionServer.java
@Override protected void serviceInit(Configuration conf) throws Exception { super.serviceInit(conf); LOG.info("initialize service - " + getName()); sessions = new ConcurrentHashMap<>(); int sessMax = conf.getInt(OctopusConfiguration.MASTER_SESSION_MAX, EXECUTOR_MAX_DEFAULT); LOG.debug("create ThreadPoolExecutor for sessions (" + OctopusConfiguration.MASTER_SERVER_ADDRESS + '=' + sessMax + ')'); executor = new ThreadPoolExecutor(0, sessMax, EXECUTOR_KEEPALIVE_DEFAULT, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); listener = new Listener(); LOG.debug("thread " + listener.getName() + " is created"); }
From source file:com.oneops.util.ReliableExecutor.java
public ReliableExecutor(int threadPoolSize, boolean doSyncOnRejection) { this.threadPoolSize = threadPoolSize; RejectedExecutionHandler handler; if (doSyncOnRejection) { handler = new ThreadPoolExecutor.CallerRunsPolicy(); } else {//from w ww . jav a 2 s. com handler = new ThreadPoolExecutor.AbortPolicy(); } executors = new ThreadPoolExecutor(0, threadPoolSize, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), handler); }
From source file:com.tesobe.obp.transport.spi.ConnectorNov2016Test.java
@Before public void connector() { Transport.Factory factory = Transport.factory(Transport.Version.Nov2016, Transport.Encoding.json) .map(Function.identity()).orElseThrow(IllegalArgumentException::new); Receiver receiver = new ReceiverNov2016(new MockResponder(), factory.codecs()); final BlockingQueue<String> in = new SynchronousQueue<>(); final BlockingQueue<Message> out = new SynchronousQueue<>(); final Sender sender = request -> { out.put(request);/*from ww w .j a v a 2 s . com*/ return in.take(); }; // north: sender connector = factory.connector(sender); // south: receiver in a background thread service.submit(new Callable<Void>() { @Override @SuppressWarnings({ "InfiniteLoopStatement" }) public Void call() throws InterruptedException { for (;;) { in.put(receiver.respond(out.take())); } } }); }
From source file:com.l2jfree.gameserver.ThreadPoolManager.java
private ThreadPoolManager() { final int instantPoolSize = Math.max(1, Config.THREAD_POOL_SIZE / 3); _scheduledPool = new ScheduledThreadPoolExecutor(Config.THREAD_POOL_SIZE - instantPoolSize); _scheduledPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler()); _scheduledPool.prestartAllCoreThreads(); _instantPool = new ThreadPoolExecutor(instantPoolSize, instantPoolSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100000)); _instantPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler()); _instantPool.prestartAllCoreThreads(); _longRunningPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); _longRunningPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler()); _longRunningPool.prestartAllCoreThreads(); scheduleAtFixedRate(new Runnable() { @Override/* ww w . java 2 s .c om*/ public void run() { purge(); } }, 60000, 60000); _log.info("ThreadPoolManager: Initialized with " + _scheduledPool.getPoolSize() + " scheduler, " + _instantPool.getPoolSize() + " instant, " + _longRunningPool.getPoolSize() + " long running thread(s)."); }
From source file:org.apache.hadoop.hbase.procedure.ProcedureMember.java
/** * Default thread pool for the procedure * * @param memberName//from w ww . ja v a 2s. c o m * @param procThreads the maximum number of threads to allow in the pool * @param keepAliveMillis the maximum time (ms) that excess idle threads will wait for new tasks */ public static ThreadPoolExecutor defaultPool(String memberName, int procThreads, long keepAliveMillis) { return new ThreadPoolExecutor(1, procThreads, keepAliveMillis, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new DaemonThreadFactory("member: '" + memberName + "' subprocedure-pool")); }
From source file:com.l2jfree.util.concurrent.L2ThreadPool.java
public static void initThreadPools(ThreadPoolInitializer initializer) throws Exception { if (!ArrayUtils.isEmpty(_scheduledPools) || !ArrayUtils.isEmpty(_instantPools) || !ArrayUtils.isEmpty(_longRunningPools)) throw new Exception("The thread pool has been already set!"); initializer.initThreadPool();//from w ww. j a v a 2s . c om _scheduledPools = initializer.getScheduledPools(); _instantPools = initializer.getInstantPools(); _longRunningPools = initializer.getLongRunningPools(); if (ArrayUtils.isEmpty(_scheduledPools)) { _log.info("No scheduled thread pool has been manually initialized, so initializing default one."); _scheduledPools = new ScheduledThreadPoolExecutor[] { new ScheduledThreadPoolExecutor( // // int corePoolSize 4) }; } if (ArrayUtils.isEmpty(_instantPools)) { _log.info("No instant thread pool has been manually initialized, so initializing default one."); _instantPools = new ThreadPoolExecutor[] { new ThreadPoolExecutor( // // int corePoolSize 0, // int maximumPoolSize Integer.MAX_VALUE, // long keepAliveTime 60L, // TimeUnit unit TimeUnit.SECONDS, // BlockingQueue<Runnable> workQueue new SynchronousQueue<Runnable>()) }; } if (ArrayUtils.isEmpty(_longRunningPools)) { _log.info("No long running thread pool has been manually initialized, so initializing default one."); _longRunningPools = new ThreadPoolExecutor[] { new ThreadPoolExecutor( // // int corePoolSize 0, // int maximumPoolSize Integer.MAX_VALUE, // long keepAliveTime 60L, // TimeUnit unit TimeUnit.SECONDS, // BlockingQueue<Runnable> workQueue new SynchronousQueue<Runnable>()) }; } for (ThreadPoolExecutor threadPool : getThreadPools()) { threadPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler()); threadPool.prestartAllCoreThreads(); } scheduleAtFixedRate(new Runnable() { @Override public void run() { purge(); } }, 60000, 60000); _log.info("L2ThreadPool: Initialized with"); _log.info("\t... " + getPoolSize(_scheduledPools) + "/" + getMaximumPoolSize(_scheduledPools) + " scheduler,"); _log.info("\t... " + getPoolSize(_instantPools) + "/" + getMaximumPoolSize(_instantPools) + " instant,"); _log.info("\t... " + getPoolSize(_longRunningPools) + "/" + getMaximumPoolSize(_longRunningPools) + " long running thread(s)."); }
From source file:org.apache.sqoop.mapreduce.SQLServerAsyncDBExecThread.java
/** * Create a new thread that interacts with the database. *///from ww w .j a v a 2 s . c o m public SQLServerAsyncDBExecThread() { recordListQueue = new SynchronousQueue<List<SqoopRecord>>(); }