List of usage examples for java.util.concurrent ThreadFactory ThreadFactory
ThreadFactory
From source file:com.reactivetechnologies.blaze.throttle.DefaultConsumerThrottler.java
@PostConstruct public void init() { if (enabled) { addCommand(new ThrottleCommand()); List<? extends Command> customCommands = loadCommands(); if (customCommands != null) { for (Command cmd : customCommands) addCommand(cmd);/*from w w w . j a v a 2s .c om*/ } counter = new AtomicInteger(); timer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable arg0) { Thread t = new Thread(arg0, "Throttler-timer-thread"); t.setDaemon(true); return t; } }); timer.scheduleWithFixedDelay(new MessageThrottlerTask(), 0, throttlerPeriod, TimeUnit.MILLISECONDS); log.info("Throttling enabled with period of " + throttlerPeriod + " millis"); } }
From source file:org.apache.nifi.remote.client.http.HttpClient.java
public HttpClient(final SiteToSiteClientConfig config) { super(config); peerSelector = new PeerSelector(this, config.getPeerPersistenceFile()); peerSelector.setEventReporter(config.getEventReporter()); taskExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() { private final ThreadFactory defaultFactory = Executors.defaultThreadFactory(); @Override/*from w w w . j av a 2 s.co m*/ public Thread newThread(final Runnable r) { final Thread thread = defaultFactory.newThread(r); thread.setName("Http Site-to-Site PeerSelector"); thread.setDaemon(true); return thread; } }); taskExecutor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { peerSelector.refreshPeers(); } }, 0, 5, TimeUnit.SECONDS); }
From source file:com.chicm.cmraft.core.NodeConnectionManager.java
public void appendEntries(RaftLog logMgr, long lastApplied) { int nServers = getRemoteServers().size(); if (nServers <= 0) { return;/*from w ww. j ava 2 s. c o m*/ } ExecutorService executor = Executors.newFixedThreadPool(nServers, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(getRaftNode().getName() + "-AsyncRpcCaller" + (byte) System.currentTimeMillis()); return t; } }); for (ServerInfo server : getRemoteServers()) { NodeConnection conn = connections.get(server); long startIndex = logMgr.getFollowerMatchIndex(server) + 1; LOG.info(getRaftNode().getName() + ": SENDING appendEntries Request TO: " + server); Thread t = new Thread(new AsynchronousAppendEntriesWorker(getRaftNode(), conn, getRaftNode().getRaftLog(), getRaftNode().getServerInfo(), getRaftNode().getCurrentTerm(), logMgr.getCommitIndex(), startIndex - 1, logMgr.getLogTerm(startIndex - 1), logMgr.getLogEntries(startIndex, lastApplied), lastApplied)); t.setDaemon(true); executor.execute(t); } }
From source file:org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.RamDiskAsyncLazyPersistService.java
private void addExecutorForVolume(final File volume) { ThreadFactory threadFactory = new ThreadFactory() { @Override//w w w . j ava 2 s . c o m public Thread newThread(Runnable r) { Thread t = new Thread(threadGroup, r); t.setName("Async RamDisk lazy persist worker for volume " + volume); return t; } }; 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(volume, executor); }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.MessageManager.java
/** * Creates a new instance with a Gal controller reference. * /*from w ww. j a v a 2s . c o m*/ * @param _gal * a Gal controller reference. */ public MessageManager(GalController _gal) { gal = _gal; executor = Executors.newFixedThreadPool(getGal().getPropertiesManager().getNumberOfThreadForAnyPool(), new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "THPool-MessageManager"); } }); if (executor instanceof ThreadPoolExecutor) { ((ThreadPoolExecutor) executor).setKeepAliveTime(getGal().getPropertiesManager().getKeepAliveThread(), TimeUnit.MINUTES); ((ThreadPoolExecutor) executor).allowCoreThreadTimeOut(true); } }
From source file:com.clustercontrol.systemlog.util.SyslogReceiver.java
public synchronized void start() throws SocketException, UnknownHostException { log.info(String.format("starting SyslogReceiver. [address = %s, port = %s, charset = %s, handler = %s]", listenAddress, listenPort, charset.name(), _handler.getClass().getName())); // ?????????handler, receiver, socket????? // ???Hinemos???Listen??? if (!HinemosManagerMain._isClustered) { socket = new DatagramSocket(listenPort, InetAddress.getByName(listenAddress)); socket.setReceiveBufferSize(socketBufferSize); socket.setSoTimeout(socketTimeout); }// ww w . ja va 2 s . c om _executor = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "SystemLogReceiver"); } }); _handler.start(); if (!HinemosManagerMain._isClustered) { _executor.submit(new ReceiverTask(socket, _handler)); } }
From source file:pt.lsts.neptus.util.logdownload.LogsDownloaderWorkerUtil.java
/** * Creates a {@link ScheduledThreadPoolExecutor} for use on {@link LogsDownloaderWorker}. * //w ww . j a v a 2s . c om * @param caller * @return */ static ScheduledThreadPoolExecutor createThreadPool(LogsDownloaderWorker caller) { ScheduledThreadPoolExecutor ret = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(4, new ThreadFactory() { private ThreadGroup group; private long count = 0; { SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); } @Override public Thread newThread(Runnable r) { Thread t = new Thread(group, r); t.setName(caller.getClass().getSimpleName() + "::" + Integer.toHexString(caller.hashCode()) + "::" + count++); t.setDaemon(true); return t; } }); return ret; }
From source file:com.reactive.hzdfs.core.DistributedFileSupportService.java
@PostConstruct private void init() { commandTopicId = hzService.addMessageChannel(this); threads = Executors.newFixedThreadPool(nThreads, new ThreadFactory() { int n = 0; @Override//from w w w .ja v a 2 s . com public Thread newThread(Runnable r) { Thread t = new Thread(r, "DFSS-Worker-" + (n++)); return t; } }); recordMapCfg = RecordMapConfig.class.getAnnotation(IMapConfig.class); log.info("[DFSS] File distribution service initialized"); }
From source file:org.apache.synapse.commons.beanstalk.enterprise.EnterpriseBeanstalkManager.java
/** * Initializes the beanstalk manager, which creates and initializes beanstalk defined in the * given Properties instance.//from ww w .j a va 2s. c o m * @param props Properties to read beanstalk configurations from. Usually, source of this is * synapse.properties file. */ public void init(Properties props) { if (props == null) { if (log.isDebugEnabled()) { log.debug("Beanstalk properties cannot be found."); } return; } String beanstalkNameList = MiscellaneousUtil.getProperty(props, EnterpriseBeanstalkConstants.SYNAPSE_BEANSTALK_PREFIX, null); if (beanstalkNameList == null || "".equals(beanstalkNameList)) { if (log.isDebugEnabled()) { log.debug("No beanstalks defined for initialization."); } return; } String[] beanstalkNames = beanstalkNameList.split(","); if (beanstalkNames == null || beanstalkNames.length == 0) { if (log.isDebugEnabled()) { log.debug("No beanstalk definitions found for initialization."); } return; } scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "enterprise-beanstalk-cleaner"); } }); for (String beanstalkName : beanstalkNames) { if (beanstalkName == null || beanstalkName.trim().length() == 0) { continue; } String propertyPrefix = EnterpriseBeanstalkConstants.SYNAPSE_BEANSTALK_PREFIX + "." + beanstalkName + "."; Properties currentBeanstalkProps = new Properties(); for (Map.Entry<Object, Object> entry : props.entrySet()) { if (entry.getKey() instanceof String && entry.getValue() instanceof String) { String key = (String) entry.getKey(); if (key.startsWith(propertyPrefix)) { currentBeanstalkProps.setProperty(key.replace(propertyPrefix, ""), (String) entry.getValue()); } } } EnterpriseBeanstalk beanstalk = new EnterpriseBeanstalk(beanstalkName, currentBeanstalkProps, scheduler); beanstalk.init(); beanstalkMap.put(beanstalkName, beanstalk); } }
From source file:org.jenkinsci.remoting.protocol.IOHubRule.java
/** * {@inheritDoc}// w ww .j a va2s. co m */ @Override public Statement apply(final Statement base, final Description description) { Skip skip = description.getAnnotation(Skip.class); if (skip != null && (skip.value().length == 0 || Arrays.asList(skip.value()).contains(id))) { return base; } final AtomicInteger counter = new AtomicInteger(); return new Statement() { @Override public void evaluate() throws Throwable { executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2 - 1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, String.format("%s%s-%d", description.getDisplayName(), id == null || id.isEmpty() ? "" : "-" + id, counter.incrementAndGet())); } }); selector = IOHub.create(executorService); try { base.evaluate(); } finally { IOUtils.closeQuietly(selector); selector = null; executorService.shutdownNow(); executorService = null; } } }; }