List of usage examples for java.util.concurrent Executors defaultThreadFactory
public static ThreadFactory defaultThreadFactory()
From source file:edu.umass.cs.reconfiguration.SQLReconfiguratorDB.java
private boolean initCheckpointServer() { this.executor = Executors.newScheduledThreadPool(THREAD_POOL_SIZE, new ThreadFactory() { @Override//from ww w. ja va 2s . co m public Thread newThread(Runnable r) { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setName(SQLReconfiguratorDB.class.getSimpleName() + myID); return thread; } }); try { InetAddress addr = null; try { this.serverSock = new ServerSocket(); // first try the configured address, else fall back to wildcard this.serverSock .bind(new InetSocketAddress(addr = this.consistentNodeConfig.getBindAddress(myID), 0)); } catch (IOException ioe) { log.info(this + " unable to open large checkpoint server socket on " + addr + "; trying wildcard address instead"); this.serverSock = new ServerSocket(0); } checkpointServerFuture = executor.submit(new CheckpointServer()); return true; } catch (IOException e) { log.severe(this + " unable to open server socket for large checkpoint transfers"); e.printStackTrace(); } return false; }
From source file:org.apache.cassandra.concurrent.ContinuationsExecutor.java
/** * Creates a new {@code ContinuationsExecutor} with the given initial * parameters and default thread factory and rejected execution handler. It * may be more convenient to use one of the {@link Executors} factory * methods instead of this general purpose constructor. * /*from www. j a va 2s . co m*/ * @param corePoolSize * the number of threads to keep in the pool, even if they are * idle, unless {@code allowCoreThreadTimeOut} is set * @param maximumPoolSize * the maximum number of threads to allow in the pool * @param keepAliveTime * when the number of threads is greater than the core, this is * the maximum time that excess idle threads will wait for new * tasks before terminating. * @param unit * the time unit for the {@code keepAliveTime} argument * @param workQueue * the queue to use for holding tasks before they are executed. * This queue will hold only the {@code Runnable} tasks submitted * by the {@code execute} method. * @throws IllegalArgumentException * if one of the following holds:<br> * {@code corePoolSize < 0}<br> * {@code keepAliveTime < 0}<br> * {@code maximumPoolSize <= 0}<br> * {@code maximumPoolSize < corePoolSize} * @throws NullPointerException * if {@code workQueue} is null */ public ContinuationsExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), defaultHandler); }
From source file:fr.efl.chaine.xslt.GauloisPipe.java
protected ThreadFactory getThreadFactory() { if (threadFactory == null) { threadFactory = Executors.defaultThreadFactory(); } return threadFactory; }
From source file:org.apache.cassandra.concurrent.ContinuationsExecutor.java
/** * Creates a new {@code ContinuationsExecutor} with the given initial * parameters and default thread factory. * //from ww w . j a v a 2 s . c om * @param corePoolSize * the number of threads to keep in the pool, even if they are * idle, unless {@code allowCoreThreadTimeOut} is set * @param maximumPoolSize * the maximum number of threads to allow in the pool * @param keepAliveTime * when the number of threads is greater than the core, this is * the maximum time that excess idle threads will wait for new * tasks before terminating. * @param unit * the time unit for the {@code keepAliveTime} argument * @param workQueue * the queue to use for holding tasks before they are executed. * This queue will hold only the {@code Runnable} tasks submitted * by the {@code execute} method. * @param handler * the handler to use when execution is blocked because the * thread bounds and queue capacities are reached * @throws IllegalArgumentException * if one of the following holds:<br> * {@code corePoolSize < 0}<br> * {@code keepAliveTime < 0}<br> * {@code maximumPoolSize <= 0}<br> * {@code maximumPoolSize < corePoolSize} * @throws NullPointerException * if {@code workQueue} or {@code handler} is null */ public ContinuationsExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), handler); }
From source file:org.hyperledger.fabric.sdk.ServiceDiscovery.java
void run() { if (channel.isShutdown() || SERVICE_DISCOVER_FREQ_SECONDS < 1) { return;/* www .j a v a 2 s .co m*/ } if (seviceDiscovery == null) { seviceDiscovery = Executors.newSingleThreadScheduledExecutor(r -> { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; }).scheduleAtFixedRate(() -> { logger.debug(format("Channel %s starting service rediscovery after %d seconds.", channelName, SERVICE_DISCOVER_FREQ_SECONDS)); fullNetworkDiscovery(true); }, SERVICE_DISCOVER_FREQ_SECONDS, SERVICE_DISCOVER_FREQ_SECONDS, TimeUnit.SECONDS); } }
From source file:org.apache.lens.server.query.QueryExecutionServiceImpl.java
private void startEstimatePool() { int minPoolSize = conf.getInt(ESTIMATE_POOL_MIN_THREADS, DEFAULT_ESTIMATE_POOL_MIN_THREADS); int maxPoolSize = conf.getInt(ESTIMATE_POOL_MAX_THREADS, DEFAULT_ESTIMATE_POOL_MAX_THREADS); int keepAlive = conf.getInt(ESTIMATE_POOL_KEEP_ALIVE_MILLIS, DEFAULT_ESTIMATE_POOL_KEEP_ALIVE_MILLIS); final ThreadFactory defaultFactory = Executors.defaultThreadFactory(); final AtomicInteger thId = new AtomicInteger(); // We are creating our own thread factory, just so that we can override thread name for easy debugging ThreadFactory threadFactory = new ThreadFactory() { @Override//from w w w .j a va2s .c o m public Thread newThread(Runnable r) { Thread th = defaultFactory.newThread(r); th.setName("estimate-" + thId.incrementAndGet()); return th; } }; log.debug("starting estimate pool"); ThreadPoolExecutor estimatePool = new ThreadPoolExecutor(minPoolSize, maxPoolSize, keepAlive, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), threadFactory); estimatePool.allowCoreThreadTimeOut(false); estimatePool.prestartCoreThread(); this.estimatePool = estimatePool; }
From source file:org.apache.lens.server.query.QueryExecutionServiceImpl.java
private void startLauncherPool() { int minPoolSize = conf.getInt(LAUNCHER_POOL_MIN_THREADS, DEFAULT_LAUNCHER_POOL_MIN_THREADS); int maxPoolSize = conf.getInt(LAUNCHER_POOL_MAX_THREADS, DEFAULT_LAUNCHER_POOL_MAX_THREADS); int keepAlive = conf.getInt(LAUNCHER_POOL_KEEP_ALIVE_MILLIS, DEFAULT_LAUNCHER_POOL_KEEP_ALIVE_MILLIS); final ThreadFactory defaultFactory = Executors.defaultThreadFactory(); final AtomicInteger thId = new AtomicInteger(); // We are creating our own thread factory, just so that we can override thread name for easy debugging ThreadFactory threadFactory = new ThreadFactory() { @Override//w w w . j a v a 2 s . com public Thread newThread(Runnable r) { Thread th = defaultFactory.newThread(r); th.setName("launcher-" + thId.incrementAndGet()); return th; } }; log.debug("starting query launcher pool"); ThreadPoolExecutor launcherPool = new ThreadPoolExecutor(minPoolSize, maxPoolSize, keepAlive, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), threadFactory); launcherPool.allowCoreThreadTimeOut(false); launcherPool.prestartCoreThread(); this.queryLauncherPool = launcherPool; }
From source file:org.orcid.core.manager.impl.OrcidProfileManagerImpl.java
private ExecutorService createThreadPoolForIndexing() { return new ThreadPoolExecutor(numberOfIndexingThreads, numberOfIndexingThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(INDEXING_BATCH_SIZE), Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:org.hyperledger.fabric.sdk.Channel.java
void runSweeper() { if (shutdown || DELTA_SWEEP < 1) { return;//from w w w. ja v a 2 s .com } if (sweeper == null) { sweeperExecutorService = Executors.newSingleThreadScheduledExecutor(r -> { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; }); sweeper = sweeperExecutorService.scheduleAtFixedRate(() -> { try { if (txListeners != null) { synchronized (txListeners) { for (Iterator<Map.Entry<String, LinkedList<TL>>> it = txListeners.entrySet() .iterator(); it.hasNext();) { Map.Entry<String, LinkedList<TL>> es = it.next(); LinkedList<TL> tlLinkedList = es.getValue(); tlLinkedList.removeIf(TL::sweepMe); if (tlLinkedList.isEmpty()) { it.remove(); } } } } } catch (Exception e) { logger.warn("Sweeper got error:" + e.getMessage(), e); } }, 0, DELTA_SWEEP, TimeUnit.MILLISECONDS); } }