List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:org.batoo.jpa.benchmark.BenchmarkTest.java
private ThreadPoolExecutor createExecutor(BlockingQueue<Runnable> workQueue) { final AtomicInteger nextThreadNo = new AtomicInteger(0); final ThreadPoolExecutor executor = new ThreadPoolExecutor(// BenchmarkTest.THREAD_COUNT, BenchmarkTest.THREAD_COUNT, // min max threads 0L, TimeUnit.MILLISECONDS, // the keep alive time - hold it forever workQueue, new ThreadFactory() { @Override//from w w w .jav a 2 s . com public Thread newThread(Runnable r) { final Thread t = new Thread(r); t.setDaemon(true); t.setPriority(Thread.NORM_PRIORITY); t.setName("Benchmark-" + nextThreadNo.get()); BenchmarkTest.this.threadIds[nextThreadNo.getAndIncrement()] = t.getId(); return t; } }); executor.prestartAllCoreThreads(); return executor; }
From source file:co.cask.cdap.internal.app.runtime.spark.SparkRuntimeService.java
@Override protected Executor executor() { // Always execute in new daemon thread. return new Executor() { @Override//w w w. j av a2 s . c o m public void execute(final Runnable runnable) { final Thread t = new Thread(new Runnable() { @Override public void run() { // note: this sets logging context on the thread level LoggingContextAccessor.setLoggingContext(context.getLoggingContext()); runnable.run(); } }); t.setDaemon(true); t.setName(getServiceName()); t.start(); } }; }
From source file:org.apache.nifi.registry.security.ldap.tenants.LdapUserGroupProvider.java
@Override public void initialize(final UserGroupProviderInitializationContext initializationContext) throws SecurityProviderCreationException { ldapSync = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { final ThreadFactory factory = Executors.defaultThreadFactory(); @Override//from w ww .j a va 2 s . c om public Thread newThread(Runnable r) { final Thread thread = factory.newThread(r); thread.setName(String.format("%s (%s) - background sync thread", getClass().getSimpleName(), initializationContext.getIdentifier())); return thread; } }); }
From source file:org.broadinstitute.gatk.engine.phonehome.GATKRunReport.java
/** * Post this GATK report to the AWS s3 GATK_Run_Report log * * @return the s3Object pointing to our pushed report, or null if we failed to push *//*from w w w .ja v a 2s. c om*/ protected S3Object postReportToAWSS3() { // modifying example code from http://jets3t.s3.amazonaws.com/toolkit/code-samples.html this.hostName = Utils.resolveHostname(); // we want to fill in the host name final String key = getReportFileName(); logger.debug("Generating GATK report to AWS S3 with key " + key); try { // create an byte output stream so we can capture the output as a byte[] final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(8096); final OutputStream outputStream = new GZIPOutputStream(byteStream); postReportToStream(outputStream); outputStream.close(); final byte[] report = byteStream.toByteArray(); // stop us from printing the annoying, and meaningless, mime types warning final Logger mimeTypeLogger = Logger.getLogger(org.jets3t.service.utils.Mimetypes.class); mimeTypeLogger.setLevel(Level.FATAL); // Set the S3 upload on its own thread with timeout: final S3PutRunnable s3run = new S3PutRunnable(key, report); final Thread s3thread = new Thread(s3run); s3thread.setDaemon(true); s3thread.setName("S3Put-Thread"); s3thread.start(); s3thread.join(s3PutTimeOutInMilliseconds); if (s3thread.isAlive()) { s3thread.interrupt(); exceptDuringRunReport("Run statistics report upload to AWS S3 timed-out"); } else if (s3run.isSuccess.get()) { logger.info("Uploaded run statistics report to AWS S3"); logger.debug("Uploaded to AWS: " + s3run.s3Object); return s3run.s3Object; } else { // an exception occurred, the thread should have already invoked the exceptDuringRunReport function } } catch (IOException e) { exceptDuringRunReport("Couldn't read report file", e); } catch (InterruptedException e) { exceptDuringRunReport("Run statistics report upload interrupted", e); } return null; }
From source file:com.zavakid.mushroom.impl.TestSinkQueue.java
private SinkQueue<Integer> newSleepingConsumerQueue(int capacity, int... values) { final SinkQueue<Integer> q = new SinkQueue<Integer>(capacity); final Semaphore semaphore = new Semaphore(0); for (int i : values) { q.enqueue(i);//ww w .j a v a 2 s. c o m } Thread t = new Thread() { @Override public void run() { try { q.consume(new Consumer<Integer>() { public void consume(Integer e) throws InterruptedException { semaphore.release(1); LOG.info("sleeping"); Thread.sleep(1000 * 86400); // a long time } }); } catch (InterruptedException ex) { LOG.warn("Interrupted", ex); } } }; t.setName("Sleeping consumer"); t.setDaemon(true); // so jvm can exit t.start(); try { semaphore.acquire(); } catch (InterruptedException e) { e.printStackTrace(); } LOG.debug("Returning new sleeping consumer queue"); return q; }
From source file:org.apache.nifi.ldap.tenants.LdapUserGroupProvider.java
@Override public void initialize(final UserGroupProviderInitializationContext initializationContext) throws AuthorizerCreationException { ldapSync = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { final ThreadFactory factory = Executors.defaultThreadFactory(); @Override//from w w w.j a v a 2 s . c om public Thread newThread(Runnable r) { final Thread thread = factory.newThread(r); thread.setName(String.format("%s (%s) - background sync thread", getClass().getSimpleName(), initializationContext.getIdentifier())); return thread; } }); }
From source file:net.xmind.workbench.internal.notification.SiteEventNotificationService.java
private void showNotifications(final List<ISiteEvent> events) { if (workbench == null) return;/*from ww w .j a v a2s .c o m*/ if (canShowNotifications()) { doShowNotifications(events); } else { Thread thread = new Thread(new Runnable() { public void run() { while (!canShowNotifications()) { try { Thread.sleep(5000); } catch (InterruptedException e) { return; } } doShowNotifications(events); } }); thread.setPriority(Thread.MIN_PRIORITY); thread.setDaemon(true); thread.setName("WaitToShowNotifications"); //$NON-NLS-1$ thread.start(); } }
From source file:org.talend.commons.utils.threading.Locker.java
private void initThreadsPool() { treadsPool = Executors.newCachedThreadPool(new ThreadFactory() { @Override//from ww w. j a va 2s . com public Thread newThread(Runnable r) { Thread newThread = Executors.defaultThreadFactory().newThread(r); newThread.setName(newThread.getName() + "_" + Locker.class.getSimpleName()); //$NON-NLS-1$ return newThread; } }); }
From source file:org.jumpmind.symmetric.service.impl.RouterService.java
protected IDataToRouteReader startReading(ChannelRouterContext context) { IDataToRouteReader reader = new DataGapRouteReader(context, engine); if (parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)) { reader.run();/*from ww w . java 2 s.c o m*/ } else { if (readThread == null) { readThread = Executors.newCachedThreadPool(new ThreadFactory() { final AtomicInteger threadNumber = new AtomicInteger(1); final String namePrefix = parameterService.getEngineName().toLowerCase() + "-router-reader-"; public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(namePrefix + threadNumber.getAndIncrement()); if (t.isDaemon()) { t.setDaemon(false); } if (t.getPriority() != Thread.NORM_PRIORITY) { t.setPriority(Thread.NORM_PRIORITY); } return t; } }); } readThread.execute(reader); } return reader; }
From source file:org.openqa.selenium.server.SeleniumDriverResourceHandler.java
private void shutDown(HttpResponse res) { log.info("Shutdown command received"); Runnable initiateShutDown = new Runnable() { public void run() { log.info("initiating shutdown"); Sleeper.sleepTight(500);/*from w w w. j av a2 s . c o m*/ System.exit(0); } }; Thread isd = new Thread(initiateShutDown); // Thread safety reviewed isd.setName("initiateShutDown"); isd.start(); if (res != null) { try { res.getOutputStream().write("OK".getBytes()); res.commit(); } catch (IOException e) { throw new RuntimeException(e); } } }