List of usage examples for java.util.concurrent ThreadFactory ThreadFactory
ThreadFactory
From source file:org.xenmaster.monitoring.MonitoringAgent.java
protected final void setUpEngine() { engine = Executors.newCachedThreadPool(new ThreadFactory() { @Override/*from w ww . j a v a 2s. co m*/ public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Monitoring engine " + r.getClass().getSimpleName()); return t; } }); SequenceBarrier collectorBarrier = ringBuffer.newBarrier(); BatchEventProcessor<Record> cr = new BatchEventProcessor<>(ringBuffer, collectorBarrier, collector); SequenceBarrier correlatorBarrier = ringBuffer.newBarrier(cr.getSequence()); BatchEventProcessor<Record> cb = new BatchEventProcessor<>(ringBuffer, correlatorBarrier, correl); ringBuffer.setGatingSequences(cb.getSequence()); engine.execute(cr); engine.execute(cb); }
From source file:org.hyperic.hq.agent.server.CommandListener.java
private void setupThreadPools() { for (final String cmdName : THREAD_POOLS) { final String poolName = cmdName.replace(AgentCommandsAPI.commandPrefix, ""); final ExecutorService pool = Executors.newFixedThreadPool(1, new ThreadFactory() { private final AtomicLong num = new AtomicLong(0); public Thread newThread(Runnable r) { Thread rtn = new Thread(r, "commandlistener-" + poolName + "-" + num.getAndIncrement()); rtn.setDaemon(true);// w w w .j ava 2s .c o m return rtn; } }); threadPools.put(cmdName, pool); } }
From source file:com.linkedin.pinot.controller.helix.core.relocation.RealtimeSegmentRelocator.java
public RealtimeSegmentRelocator(PinotHelixResourceManager pinotHelixResourceManager, ControllerConf config) { _pinotHelixResourceManager = pinotHelixResourceManager; _helixManager = pinotHelixResourceManager.getHelixZkManager(); _helixAdmin = pinotHelixResourceManager.getHelixAdmin(); _runFrequencySeconds = getRunFrequencySeconds(config.getRealtimeSegmentRelocatorFrequency()); _executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override/* ww w .j a v a 2 s . com*/ public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); thread.setName("RealtimeSegmentRelocatorExecutorService"); return thread; } }); }
From source file:nuclei.task.TaskPool.java
TaskPool(Looper mainLooper, final String name, int maxThreads, List<TaskInterceptor> interceptors) { this.name = name; TASK_POOLS.put(name, this); this.interceptors = interceptors; handler = new Handler(mainLooper, this); BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(128); taskRunnablePool = new Pools.SimplePool<>(maxThreads); taskQueues = new Pools.SimplePool<>(10); maxThreads = Math.max(CORE_POOL_SIZE, maxThreads); poolExecutor = new ThreadPoolExecutor(CORE_POOL_SIZE, maxThreads, 1, TimeUnit.SECONDS, workQueue, new ThreadFactory() { private final AtomicInteger mCount = new AtomicInteger(1); @Override/*from w ww . j a va2 s. c om*/ public Thread newThread(@NonNull Runnable r) { return new Thread(r, name + " #" + mCount.incrementAndGet()); } }); if (LISTENER != null) LISTENER.onCreated(this); }
From source file:net.sourceforge.subsonic.service.PodcastService.java
public PodcastService() { ThreadFactory threadFactory = new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true);//w w w .j av a 2 s. co m return t; } }; refreshExecutor = Executors.newFixedThreadPool(5, threadFactory); downloadExecutor = Executors.newFixedThreadPool(3, threadFactory); scheduledExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory); }
From source file:com.google.devtools.build.lib.bazel.dash.DashModule.java
public DashModule() { // Make sure sender != null before we hop on the event bus. sender = NO_OP_SENDER;//from w w w. j av a 2s. c o m executorService = Executors.newFixedThreadPool(5, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setDaemon(true); return thread; } }); }
From source file:org.deeplearning4j.arbiter.optimize.runner.BaseOptimizationRunner.java
protected void init() { futureListenerExecutor = Executors.newFixedThreadPool(maxConcurrentTasks(), new ThreadFactory() { private AtomicLong counter = new AtomicLong(0); @Override/*from ww w. j ava 2 s . co m*/ public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); t.setName("ArbiterOptimizationRunner-" + counter.getAndIncrement()); return t; } }); }
From source file:minium.script.rhinojs.RhinoEngine.java
public <T> RhinoEngine(final RhinoProperties properties) { this.executorService = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override/*from w ww.jav a 2 s . co m*/ public Thread newThread(Runnable r) { Preconditions.checkState(executionThread == null, "Only one thread is supported"); executionThread = FACTORY.newThread(r); return executionThread; } }); // this ensures a single thread for this engine scope = runWithContext(new RhinoCallable<Scriptable, RuntimeException>() { @Override protected Scriptable doCall(Context cx, Scriptable scope) { try { Global global = new Global(cx); RequireProperties require = properties.getRequire(); if (require != null) { List<String> modulePathURIs = getModulePathURIs(require); LOGGER.debug("Module paths: {}", modulePathURIs); global.installRequire(cx, modulePathURIs, require.isSandboxed()); } ClassLoader classloader = Thread.currentThread().getContextClassLoader(); // we need to load compat/timeout.js because rhino does not have setTimeout, setInterval, etc. cx.evaluateReader(global, new InputStreamReader(classloader.getResourceAsStream("compat/timeout.js")), "compat/timeout.js", 1, null); return global; } catch (IOException e) { throw Throwables.propagate(e); } } }); }
From source file:org.bigmouth.nvwa.transport.failover.SenderCluster.java
@Override protected void doInit() { Preconditions.checkNotNull(senderFactory, "senderFactory"); ListMultimap<EndpointKeyHost, Pair<Endpoint, Sender>> m = ArrayListMultimap.create(); senders.set(m);/*from w w w . jav a 2s . c o m*/ arrangeTaskExec = Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, SENDER_ARRANGE_THREAD_NAME); } }); this.changeMonitor.addListener(watchPath, this); }
From source file:org.hawkular.apm.performance.server.ClientSimulator.java
public void run() { Metrics metrics = new Metrics(name); ServiceRegistry reg = new DefaultServiceRegistry(systemConfig, metrics); List<PathConfiguration> paths = new ArrayList<PathConfiguration>(); for (PathConfiguration pc : systemConfig.getPaths()) { for (int i = 0; i < pc.getWeight(); i++) { paths.add(pc);/*ww w.ja va 2 s . com*/ } } // Initialise publisher metrics handler TracePublisher publisher = ServiceResolver.getSingletonService(TracePublisher.class); if (publisher == null) { log.severe("Trace publisher has not been configured correctly"); return; } publisher.setMetricHandler(new PublisherMetricHandler<Trace>() { @Override public void published(String tenantId, List<Trace> items, long metric) { metrics.publishTraces(metric); } }); Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; } }).scheduleAtFixedRate(new Runnable() { @Override public void run() { metrics.report(); } }, 1, 1, TimeUnit.SECONDS); for (int i = 0; i < requesters; i++) { new Thread(new Runnable() { @Override public void run() { System.out.println("THREAD: " + Thread.currentThread() + ": STARTED"); for (int j = 0; j < invocations; j++) { // Randomly select path int index = (int) (Math.random() * (paths.size() - 1)); Service s = reg.getServiceInstance(paths.get(index).getService()); Message m = new Message(paths.get(index).getName()); s.call(m, null, null); } System.out.println("THREAD: " + Thread.currentThread() + ": FINISHED: " + new java.util.Date()); synchronized (this) { try { wait(2000); } catch (Exception e) { e.printStackTrace(); } } } }).start(); } }