List of usage examples for java.util.concurrent ThreadFactory ThreadFactory
ThreadFactory
From source file:com.clustercontrol.selfcheck.SelfCheckTaskSubmitter.java
public SelfCheckTaskSubmitter() { _scheduler = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override//from w w w. j a v a 2 s.c o m public Thread newThread(Runnable r) { return new Thread(r, "SelfCheckScheduler"); } }); _executorService = Executors.newFixedThreadPool( HinemosPropertyUtil.getHinemosPropertyNum("selfcheck.threadpool.size", Long.valueOf(4)).intValue(), new ThreadFactory() { private volatile int _count = 0; @Override public Thread newThread(Runnable r) { return new Thread(r, "SelfCheckWorker-" + _count++); } }); }
From source file:org.bigmouth.nvwa.transport.DelegatedSender.java
@Override protected void doInit() { Preconditions.checkNotNull(this.nextSender, "nextSender"); sendExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override/*from w w w . ja va2 s.com*/ public Thread newThread(Runnable r) { return new Thread(r, threadName + "-" + idx.get()); } }); sendQueue = new LinkedBlockingQueue<Object>(pendingMessageCount); startupProcessor(); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); if (null != senderMBeanName) { DelegatedSenderMBean acceptorMBean = new DelegatedSenderMBean(this); try { ObjectName acceptorName = new ObjectName(this.senderMBeanName); mBeanServer.registerMBean(acceptorMBean, acceptorName); } catch (MalformedObjectNameException e) { LOG.error("Unable DelegatedSender jmx register:", e); } catch (NullPointerException e) { LOG.error("Unable DelegatedSender jmx register:", e); } catch (InstanceAlreadyExistsException e) { LOG.error("Unable DelegatedSender jmx register:", e); } catch (MBeanRegistrationException e) { LOG.error("Unable DelegatedSender jmx register:", e); } catch (NotCompliantMBeanException e) { LOG.error("Unable MinaSender jmx register:", e); } } }
From source file:com.astamuse.asta4d.web.util.timeout.DefaultSessionAwareTimeoutDataManager.java
@Override public void start() { // init fields dataMap = new ConcurrentHashMap<>(); dataCounter = new AtomicInteger(); service = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override//from w w w. j av a 2s. c o m public Thread newThread(Runnable r) { return new Thread(r, checkThreadName); } }); // start check thread service.scheduleAtFixedRate(new Runnable() { @Override public void run() { List<Entry<String, DataHolder>> entries = new ArrayList<>(dataMap.entrySet()); long currentTime = System.currentTimeMillis(); int removedCounter = 0; Object existing; for (Entry<String, DataHolder> entry : entries) { if (entry.getValue().isExpired(currentTime)) { existing = dataMap.remove(entry.getKey()); if (existing != null) {// we removed it successfully removedCounter++; } } } if (removedCounter > 0) { dataCounter.addAndGet(-removedCounter); } } }, expirationCheckPeriodInMilliseconds, expirationCheckPeriodInMilliseconds, TimeUnit.MILLISECONDS); }
From source file:org.apache.hadoop.hdfs.server.datanode.FSDatasetAsyncDiskService.java
/** * Create a AsyncDiskServices with a set of volumes (specified by their * root directories).// w ww. ja v a 2 s . c o m * * The AsyncDiskServices uses one ThreadPool per volume to do the async * disk operations. * * @param volumes The roots of the data volumes. */ FSDatasetAsyncDiskService(File[] volumes) { threadFactory = new ThreadFactory() { 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); } }
From source file:bigbird.benchmark.HttpBenchmark.java
public void execute() { params = getHttpParams(socketTimeout, useHttp1_0); for (RequestGenerator g : requestGenerators) { g.setParameters(params);/* w w w.ja v a 2 s.c om*/ } host = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); ThreadPoolExecutor workerPool = new ThreadPoolExecutor(threads, threads, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "ClientPool"); } }); workerPool.prestartAllCoreThreads(); BenchmarkWorker[] workers = new BenchmarkWorker[threads]; for (int i = 0; i < threads; i++) { workers[i] = new BenchmarkWorker(params, verbosity, requestGenerators[i], host, requests, keepAlive); workerPool.execute(workers[i]); } while (workerPool.getCompletedTaskCount() < threads) { Thread.yield(); try { Thread.sleep(1000); } catch (InterruptedException ignore) { } } workerPool.shutdown(); ResultProcessor.printResults(workers, host, url.toString(), contentLength); }
From source file:org.micromanager.plugins.magellan.autofocus.CrossCorrelationAutofocus.java
public CrossCorrelationAutofocus(final FixedAreaAcquisition acq, int channelIndex, double maxDisplacement, double initialPosition) { afExecutor_ = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override/*from ww w . j av a 2s . c o m*/ public Thread newThread(Runnable r) { return new Thread(r, acq.getName() + " Autofocusexecutor"); } }); channelIndex_ = channelIndex; maxDisplacement_ = maxDisplacement; acq_ = acq; initialPosition_ = initialPosition; }
From source file:org.energy_home.jemma.javagal.layers.business.implementations.ApsMessageManager.java
/** * Creates a new instance with a Gal controller reference. * /* w w w .jav a2s .co m*/ * @param _gal * a Gal controller reference. */ public ApsMessageManager(GalController _gal) { gal = _gal; executor = Executors.newFixedThreadPool(getGal().getPropertiesManager().getNumberOfThreadForAnyPool(), new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "THPool-APSMessageIndication"); } }); if (executor instanceof ThreadPoolExecutor) { ((ThreadPoolExecutor) executor).setKeepAliveTime(getGal().getPropertiesManager().getKeepAliveThread(), TimeUnit.MINUTES); ((ThreadPoolExecutor) executor).allowCoreThreadTimeOut(true); } }
From source file:io.snappydata.impl.SnappyHiveCatalog.java
public SnappyHiveCatalog() { final ThreadGroup hmsThreadGroup = LogWriterImpl.createThreadGroup(THREAD_GROUP_NAME, Misc.getI18NLogWriter());/*from w w w .ja v a 2 s.com*/ ThreadFactory hmsClientThreadFactory = new ThreadFactory() { private int next = 0; @SuppressWarnings("NullableProblems") public Thread newThread(Runnable command) { Thread t = new Thread(hmsThreadGroup, command, "HiveMetaStore Client-" + next++); t.setDaemon(true); return t; } }; hmsQueriesExecutorService = Executors.newFixedThreadPool(1, hmsClientThreadFactory); // just run a task to initialize the HMC for the thread. // Assumption is that this should be outside any lock HMSQuery q = getHMSQuery(); q.resetValues(HMSQuery.INIT, null, null, true); Future<Object> ret = hmsQueriesExecutorService.submit(q); try { ret.get(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:st.happy_camper.flume.twitter.TwitterStreamingConnection.java
/** * @param name//w w w . ja v a2s.c om * @param password * @param connectionTimeout * @throws IOException */ public TwitterStreamingConnection(String name, String password, int connectionTimeout, String[] trackedKeyword) throws IOException { httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(10 * 1000); httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(name, password)); StringBuilder content = new StringBuilder(""); for (String t : trackedKeyword) { content.append(t); content.append(","); } postContent = content.toString(); doOpen(); Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { return new Thread(runnable, "TwitterStreamingConnection"); } }).execute(new Runnable() { @Override public void run() { BlockingQueue<String> queue = TwitterStreamingConnection.this.queue; String line; while ((line = readLine()) != null) { queue.add(line); } } }); }
From source file:org.sourcepit.docker.watcher.DockerWatcher.java
public synchronized void start() { isTrue(client == null);//w w w . ja va2 s . c o m isTrue(eventObserverThread == null); isTrue(scheduler == null); final State state = new State() { @Override protected void handle(List<JsonObject> events) { DockerWatcher.this.handle(events); } }; final BlockingQueue<JsonElement> queue = new LinkedBlockingQueue<>(); client = clientFactory.createHttpClient(); final FetchConatinersCommand fetchContainersCommand = new FetchConatinersCommand(client, uri) { @Override protected void handle(JsonArray status) { LOG.debug("Fetched: {}", status.toString()); queue.add(status); } }; final DockerEventObserver eventObserver = new DockerEventObserver(client, uri) { @Override protected void handle(JsonObject event) { queue.add(event); } }; eventObserverThread = new Thread(eventObserver, "Docker Event Observer") { @Override public void interrupt() { eventObserver.die(); super.interrupt(); } }; scheduler = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "Docker State Fetcher"); } }); final SyncStateCommand syncStateCommand = new SyncStateCommand(queue) { @Override protected void requestNewStatus() { LOG.debug("Requesting new status."); scheduler.execute(fetchContainersCommand); } @Override protected void applyLastKnownState(JsonArray status) { LOG.debug("Applying new status: {}", status.toString()); state.applyLastKnownState(status); } }; scheduler.scheduleWithFixedDelay(fetchContainersCommand, 0, 30, TimeUnit.SECONDS); scheduler.scheduleWithFixedDelay(syncStateCommand, 0, 1, TimeUnit.SECONDS); eventObserverThread.start(); }