List of usage examples for java.util.concurrent ThreadFactory ThreadFactory
ThreadFactory
From source file:com.buaa.cfs.nfs3.AsyncDataService.java
public AsyncDataService() { threadFactory = new ThreadFactory() { @Override/*from ww w . j av a2 s . co m*/ public Thread newThread(Runnable r) { return new Thread(threadGroup, r); } }; 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); }
From source file:org.wso2.carbon.throttle.core.ThrottleReplicator.java
public ThrottleReplicator() { String replicatorThreads = System.getProperty("throttling.pool.size"); if (replicatorThreads != null) { replicatorPoolSize = Integer.parseInt(replicatorThreads); }/*from ww w. j a v a 2 s . c o m*/ log.debug("Replicator pool size set to " + replicatorPoolSize); ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle Replicator - " + replicatorCount++); return t; } }); String throttleFrequency = System.getProperty("throttling.replication.frequency"); if (throttleFrequency == null) { throttleFrequency = "50"; } log.debug("Throttling Frequency set to " + throttleFrequency); String maxKeysToReplicate = System.getProperty("throttling.keys.to.replicate"); if (maxKeysToReplicate != null) { keysToReplicate = Integer.parseInt(maxKeysToReplicate); } log.debug("Max keys to Replicate " + keysToReplicate); for (int i = 0; i < replicatorPoolSize; i++) { executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); } }
From source file:org.apache.synapse.commons.throttle.core.ThrottleReplicator.java
public ThrottleReplicator() { String replicatorThreads = System.getProperty("throttling.pool.size"); if (replicatorThreads != null) { replicatorPoolSize = Integer.parseInt(replicatorThreads); }/* ww w . j a va2 s .com*/ log.debug("Replicator pool size set to " + replicatorPoolSize); ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle Replicator - " + replicatorCount++); return t; } }); String throttleFrequency = System.getProperty("throttling.replication.frequency"); if (throttleFrequency == null) { throttleFrequency = "50"; } log.debug("Throttling Frequency set to " + throttleFrequency); String maxKeysToReplicate = System.getProperty("throttling.keys.to.replicate"); if (maxKeysToReplicate != null) { keysToReplicate = Integer.parseInt(maxKeysToReplicate); } log.debug("Max keys to Replicate " + keysToReplicate); for (int i = 0; i < replicatorPoolSize; i++) { executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); } }
From source file:de.uni_koeln.spinfo.maalr.sigar.SigarWrapper.java
private static void initialize() { logger.info("Initializing..."); String libBase = "/hyperic-sigar-1.6.5/sigar-bin/lib/"; try {/*w ww. ja v a 2 s.com*/ String prefix = "libsigar"; if (SystemUtils.IS_OS_WINDOWS) { prefix = "sigar"; } String arch = getSystemArch(); String suffix = getSystemSuffix(); String resourceName = prefix + "-" + arch + "-" + suffix; logger.info("Native library: " + resourceName); String resource = libBase + resourceName; URL toLoad = SigarWrapper.class.getResource(resource); File home = new File(System.getProperty("user.home")); File libs = new File(home, ".maalr/libs/sigar"); libs.mkdirs(); File tmp = new File(libs, resourceName); tmp.deleteOnExit(); FileOutputStream fos = new FileOutputStream(tmp); InputStream in = toLoad.openStream(); int i; while ((i = in.read()) != -1) { fos.write(i); } in.close(); fos.close(); logger.info("Library copied to " + tmp.getAbsolutePath()); String oldPath = System.getProperty("java.library.path"); System.setProperty("java.library.path", oldPath + SystemUtils.PATH_SEPARATOR + libs.getAbsolutePath()); logger.info("java.library.path updated: " + System.getProperty("java.library.path")); executors = Executors.newScheduledThreadPool(1, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); return t; } }); logger.info("Initialization completed."); } catch (Exception e) { logger.error("Failed to initialize!", e); } }
From source file:org.apache.hadoop.hdfs.server.datanode.DataXceiverThreadPool.java
/** * Create a pool of threads to do disk IO. * /*from w w w . j av a 2 s .co m*/ * @param conf The configuration * @param tg The ThreadGroup of all the executor threads * @param maxXceiverCount The max number of threads that can do IO. */ DataXceiverThreadPool(final Configuration conf, final ThreadGroup tg, final int maxXceiverCount) { ThreadFactory threadFactory = new ThreadFactory() { int counter = 0; @Override public Thread newThread(Runnable r) { int thisIndex; synchronized (this) { thisIndex = counter++; } Thread t = new Thread(tg, r); t.setName("disk io thread #" + thisIndex); t.setDaemon(true); return t; } }; executor = new ThreadPoolExecutor(maxXceiverCount - 1, maxXceiverCount, THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); // This can reduce the number of running threads executor.allowCoreThreadTimeOut(true); }
From source file:com.taobao.pushit.server.listener.ConnectionNumberListener.java
public ConnectionNumberListener(int connThreshold, int ipCountThreshold, int ipCheckTaskInterval) { this.connThreshold = connThreshold; this.ipCountThreshold = ipCountThreshold; this.ipCheckTaskInterval = ipCheckTaskInterval; this.scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("connection num control thread"); t.setDaemon(true);//from ww w . j a v a 2s . c o m return t; } }); this.scheduler.scheduleAtFixedRate(new Runnable() { public void run() { int ipCount = ConnectionNumberListener.this.connectionIpNumMap.size(); if (ipCount >= ConnectionNumberListener.this.ipCountThreshold) { log.warn("IP, IP, IP=" + ipCount + ", =" + ConnectionNumberListener.this.ipCountThreshold); isOverflow = true; } else { isOverflow = false; } } }, this.ipCheckTaskInterval, this.ipCheckTaskInterval, TimeUnit.SECONDS); }
From source file:org.apache.asterix.experiment.client.StatisticsQueryGenerator.java
public StatisticsQueryGenerator(StatisticsQueryGeneratorConfig config) { threadPool = Executors.newCachedThreadPool(new ThreadFactory() { private final AtomicInteger count = new AtomicInteger(); @Override/*from w w w . j a v a2s . c om*/ public Thread newThread(Runnable r) { int tid = count.getAndIncrement(); Thread t = new Thread(r, "DataGeneratorThread: " + tid); t.setDaemon(true); return t; } }); this.config = config; }
From source file:com.alibaba.wasp.fserver.SplitThread.java
/** @param server */ SplitThread(FServer server) {/*from w ww .j a v a 2 s . com*/ super(); this.server = server; this.conf = server.getConfiguration(); this.entityGroupSplitLimit = conf.getInt("wasp.fserver.entityGroupSplitLimit", Integer.MAX_VALUE); int splitThreads = conf.getInt("wasp.fserver.thread.split", 1); final String n = Thread.currentThread().getName(); this.splits = (ThreadPoolExecutor) Executors.newFixedThreadPool(splitThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-splits-" + System.currentTimeMillis()); return t; } }); }
From source file:org.opendaylight.controller.netconf.ssh.osgi.NetconfSSHActivator.java
@Override public void start(final BundleContext bundleContext) throws IOException { minaTimerExecutor = Executors.newScheduledThreadPool(POOL_SIZE, new ThreadFactory() { @Override//from www . ja va 2 s.co m public Thread newThread(final Runnable r) { return new Thread(r, "netconf-ssh-server-mina-timers"); } }); clientGroup = new NioEventLoopGroup(); nioExecutor = ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", POOL_SIZE); server = startSSHServer(bundleContext); }
From source file:io.gravitee.gateway.services.healthcheck.HealthCheckService.java
@Override protected void doStart() throws Exception { super.doStart(); eventManager.subscribeForEvents(this, ReactorEvent.class); executorService = Executors.newScheduledThreadPool(threads, new ThreadFactory() { private int counter = 0; private String prefix = "healthcheck"; public Thread newThread(Runnable r) { return new Thread(r, prefix + '-' + counter++); }//from w w w. j av a2 s .co m }); }