List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:com.baidu.fsg.uid.utils.NamingThreadFactory.java
@Override public Thread newThread(Runnable r) { Thread thread = new Thread(r); thread.setDaemon(this.daemon); // If there is no specified name for thread, it will auto detect using the invoker classname instead. // Notice that auto detect may cause some performance overhead String prefix = this.name; if (StringUtils.isBlank(prefix)) { prefix = getInvoker(2);//from ww w . j a v a 2 s .co m } thread.setName(prefix + "-" + getSequence(prefix)); // no specified uncaughtExceptionHandler, just do logging. if (this.uncaughtExceptionHandler != null) { thread.setUncaughtExceptionHandler(this.uncaughtExceptionHandler); } else { thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { LOGGER.error("unhandled exception in thread: " + t.getId() + ":" + t.getName(), e); } }); } return thread; }
From source file:com.ibm.ctg.samples.cloudmonitor.CloudMonitor.java
public CloudMonitor() throws SecurityException, IOException { log = Logger.getLogger(this.getClass().getCanonicalName()); String logName = System.getProperty(LOG_NAME_PROPERTY); if (logName != null && logName.length() > 0) { log.addHandler(new FileHandler(logName)); }/*w ww . jav a 2s . c om*/ DB_URL = System.getProperty(DB_URL_PROPERTY); Thread dbStore = new Thread(new DBStore()); dbStore.setDaemon(true); dbStore.start(); }
From source file:com.espertech.esper.epl.metric.MetricsExecutorThreaded.java
/** * Ctor./*from w w w .j a v a 2 s . c om*/ * @param engineURI engine URI */ public MetricsExecutorThreaded(final String engineURI) { ThreadFactory threadFactory = new ThreadFactory() { AtomicInteger count = new AtomicInteger(0); public Thread newThread(Runnable r) { String uri = engineURI; if (engineURI == null) { uri = "default"; } Thread t = new Thread(r); t.setName("com.espertech.esper.MetricReporting-" + uri + "-" + count.getAndIncrement()); t.setDaemon(true); return t; } }; threadPool = Executors.newCachedThreadPool(threadFactory); }
From source file:com.intuit.tank.service.impl.v1.cloud.CloudController.java
/** * @{inheritDoc//from w w w. ja v a 2 s . c o m */ public void setVmStatus(final String instanceId, final CloudVmStatus status) { Runnable task = new Runnable() { @Override public void run() { tracker.setStatus(status); if (status.getJobStatus() == JobStatus.Completed || status.getVmStatus() == VMStatus.terminated) { // will terrminate instance after waiting for some cleanup time terminator.terminate(status.getInstanceId()); // check job status and kill off instances appropriately checkJobStatus(status.getJobId(), mailService); } } }; if (status.getJobStatus() == JobStatus.Completed || status.getVmStatus() == VMStatus.terminated) { Thread t = new Thread(task); t.setDaemon(true); t.start(); } else { EXECUTOR.execute(task); } }
From source file:net.dries007.holoInventory.client.ClientHandler.java
public void init() { MinecraftForge.EVENT_BUS.register(Renderer.INSTANCE); MinecraftForge.EVENT_BUS.register(KEY_MANAGER); if (HoloInventory.getConfig().doVersionCheck) { Thread vc = new Thread(VERSION_CHECK); vc.setDaemon(true); vc.setName(Data.MODID + "VersionCheckThread"); vc.run();//from www . j av a 2 s.com MinecraftForge.EVENT_BUS.register(this); } }
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/* ww w . j av a 2 s. c o m*/ 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:gridool.db.sql.ParallelSQLExecJob.java
private static void invokeGarbageDestroyer(@Nonnull final DBAccessor dba, @Nonnull final String destroyQuery, @Nonnull final ReadWriteLock rwlock) { GarbageTableDestroyer destroyer = new GarbageTableDestroyer(destroyQuery, dba, rwlock); Thread destroyThread = new Thread(destroyer, "GarbageTableDestroyer"); destroyThread.setDaemon(true); destroyThread.start();/*from ww w.j a v a 2 s. c o m*/ }
From source file:com.codefollower.lealone.hbase.server.HBaseTcpServer.java
@Override public void start() { try {/*from w w w.j a v a2 s.co m*/ super.start(); TcpPortTracker.createTcpPortEphemeralNode(serverName, tcpPort, master != null); String name = getName() + " (" + getURL() + ")"; Thread t = new Thread(this, name); t.setDaemon(isDaemon()); t.start(); log.info("Started lealone tcp server at port " + tcpPort); } catch (SQLException e) { throw new RuntimeException(e); } }
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);/* w w w . j a 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(); } }
From source file:functionaltests.matlab.TestGetResults.java
protected void runCommand(String testName, int nb_iter, int index) throws Exception { ProcessBuilder pb = initCommand(testName, nb_iter); System.out.println("Running command : " + pb.command()); File okFile = new File(mat_tb_home + fs + "ok.tst"); File koFile = new File(mat_tb_home + fs + "ko.tst"); File reFile = new File(mat_tb_home + fs + "re.tst"); File startFile = new File(mat_tb_home + fs + "start.tst"); if (okFile.exists()) { okFile.delete();/* w ww. java 2 s . c om*/ } if (koFile.exists()) { koFile.delete(); } if (reFile.exists()) { reFile.delete(); } if (startFile.exists()) { startFile.delete(); } Process p = pb.start(); IOTools.LoggingThread lt1 = new IOTools.LoggingThread(p.getInputStream(), "[" + testName + "_" + index + "]", System.out); Thread t1 = new Thread(lt1, testName + "_" + index); t1.setDaemon(true); t1.start(); int code = p.waitFor(); while (!startFile.exists()) { Thread.sleep(100); } while (!okFile.exists() && !koFile.exists() && !reFile.exists()) { Thread.sleep(100); } if (logFile.exists()) { System.out.println(IOUtils.toString(logFile.toURI())); } if (index < nb_iter) { assertTrue(testName + "_" + index + " passed", !koFile.exists()); } else { assertTrue(testName + " passed", okFile.exists()); } }