List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:com.azaptree.services.executor.ThreadPoolConfig.java
@NotNull public ThreadFactory getThreadFactory() { if (StringUtils.isBlank(name) && !daemon) { return Executors.defaultThreadFactory(); }/*from ww w.j av a 2s . c o m*/ return new ThreadFactory() { private final AtomicInteger threadCounter = new AtomicInteger(0); @Override public Thread newThread(final Runnable r) { final Thread t = new Thread(r, String.format("%s-%d", name, threadCounter.incrementAndGet())); t.setDaemon(daemon); return t; } }; }
From source file:com.github.horrorho.liquiddonkey.cloud.Looter.java
void monitoredBackup(HttpClient client, Core core, HttpAgent agent, Backup backup) throws BadDataException, IOException, InterruptedException { // Potential for large scale memory leakage. Lightweight memory usage reporting. MemMonitor memMonitor = MemMonitor.from(config.debug().memoryMonitorIntervalMs()); try {/*from w w w. ja v a 2 s . com*/ Thread thread = new Thread(memMonitor); thread.setDaemon(true); thread.start(); // Fetch backup. backup(client, core, agent, backup); } finally { memMonitor.kill(); logger.debug("-- loot() > max sampled memory used (MB): {}", memMonitor.max() / 1048510); } }
From source file:arena.mail.MailSender.java
public void sendThreaded(MailMessage message, SendingFailureCallback... failureCallbacks) { Session session = makeSession(this.smtpServer, this.smtpServerDelimiter, this.mailProperties); Thread th = new Thread(new SendingRunnable(message, session, failureCallbacks), "mail to:" + message.getToAddress() + " subject:" + message.getSubject()); th.setDaemon(true); th.run();/* w ww .j a v a 2 s.co m*/ }
From source file:com.jkoolcloud.tnt4j.utils.TimeService.java
@Override public Thread newThread(Runnable r) { Thread task = new Thread(r, prefix + "-" + count++); task.setDaemon(true); return task;// w ww . j a va 2 s . c om }
From source file:net.sbbi.upnp.DiscoveryListener.java
private void startDevicesListenerThread() throws IOException { synchronized (singleton) { if (!inService) { this.startMultiCastSocket(); Thread deamon = new Thread(this, "DiscoveryListener daemon"); deamon.setDaemon(daemon); deamon.start();//from w w w. j a v a 2s . co m while (!inService) { // wait for the thread to be started let's wait a few ms try { Thread.sleep(2); } catch (InterruptedException ex) { // don t care } } } } }
From source file:com.example.gridtest.MyPumpStreamHandler.java
/** * Creates a stream pumper to copy the given input stream to the given * output stream./*from w w w .j a va2 s . co m*/ * * @param is the input stream to copy from * @param os the output stream to copy into * @param closeWhenExhausted close the output stream when the input stream is exhausted * @return the stream pumper thread */ protected Thread createPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) { final Thread result = new Thread(new MyStreamPumper(is, os, closeWhenExhausted)); result.setDaemon(true); return result; }
From source file:com.reactivetechnologies.platform.rest.WebbitRestServerBean.java
/** * Instantiate a REST server/*from ww w . jav a2s . co m*/ * @param port listening port * @param nThreads no of worker threads * @param annotatedPkgToScan base package to scan for JAX-RS annotated classes */ public WebbitRestServerBean(int port, int nThreads, String annotatedPkgToScan) { super(); this.annotatedPkgToScan = annotatedPkgToScan; server = new NettyWebServer(Executors.newFixedThreadPool(nThreads, new ThreadFactory() { private int n = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, "REST.Handler-" + (n++)); t.setDaemon(false); return t; } }), port).uncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error("Worker thread [" + t + "] caught unexpected exception:", e); } }); restWrapper = new Rest(server); }
From source file:com.mindquarry.desktop.event.EventBus.java
public void publishEvent(final Event event, boolean block) { log.info("publishEvent: event=" + event + ", block=" + block); if (block) {/*from w w w. j a v a2 s . c o m*/ // deliver event synchronously deliverEvent(event); } else { // deliver event asynchronously Thread thread = new Thread(new Runnable() { public void run() { // FIXME: exception handling in event deliver Thread? deliverEvent(event); } }); thread.setDaemon(true); thread.start(); } }
From source file:com.hubcap.task.TaskRunner.java
/** * Starts the ThreadPoolExecutor which builds a set of TaskRunner instances * which will wait for inputs (from the user) *///w w w.j a va 2 s. c o m public static void startThreadPool() { if (!isTaskSystemReady) { System.out.println("startThreadPool()"); isTaskSystemReady = true; // used to id the threads 'atomically' final AtomicLong count = new AtomicLong(0); if (TaskRunner.taskRunnerThreadFactory == null) { TaskRunner.taskRunnerThreadFactory = new ThreadFactory() { @Override public Thread newThread(Runnable r) { if (runningTasks.contains(r)) { throw new IllegalStateException("Cannot add duplicate runnable to running tasks"); } Thread thread = new Thread(r); thread.setDaemon(false); thread.setName("HubcapTaskRunnerThread-" + count.getAndIncrement()); taskThreads.add(thread); return thread; } }; // calculates the current stable thread count based on the // assumption // that it takes 'X' times the amount of time to transfer data // (from github) // as it does to process said data (including Gson // transformation) // and the limit of Y% use of CPU. MAX_THREADS provides a safe // and stable cap for // systems that are so 'badass' that we would break the cap. \ // (i.e. i have 32 cores and 12 disks = (2*32*12*1(1+5/1) = // 4600 threads, a bit high)...) int numThreads = ThreadUtils.getStableThreadCount(CPU_LOAD_TR, CPU_WAIT_TR, CPU_COMPUTE_TR, Constants.MAX_TASK_RUNNER_THREADS); System.out.println("creating: " + numThreads + " threads for hubcap"); TaskRunner.taskRunnerThreadPool = Executors.newFixedThreadPool(numThreads, TaskRunner.taskRunnerThreadFactory); for (int i = 0; i < numThreads; ++i) { TaskRunner tr = new TaskRunner(); taskRunnerThreadPool.execute(tr); } // pass the monitoring code to another thread // so we don't block the REPL loop monitorThread = new Thread(new Runnable() { @Override public void run() { while (!taskRunnerThreadPool.isShutdown()) { try { TaskRunner.rebalance(); Thread.sleep(Constants.POOL_SHUTDOWN_CHECK_INTERVAL); } catch (InterruptedException ex) { if (ProcessModel.instance().getVerbose()) { ErrorUtils.printStackTrace(ex); } break; } } System.out.println("Thread Pool was shutdown"); while (!taskRunnerThreadPool.isTerminated()) { try { Thread.sleep(Constants.POOL_TERM_CHECK_INTERVAL); } catch (InterruptedException ex) { ErrorUtils.printStackTrace(ex); break; } } System.out.println("Thread pool terminated."); } }); monitorThread.setName("TaskMonDaemon"); monitorThread.setDaemon(false); // start monitoring monitorThread.start(); System.out.println("Thread pool started!"); } } else { throw new IllegalStateException("Hubcap task runner can only be initialized once!"); } }
From source file:org.thomwiggers.Jjoyce.comet.CometJoyceClientRelay.java
public void run() throws JoyceException { if (this.running) throw new IllegalStateException("Already running"); this.running = true; if (this.token == null) { this.doRequest(null); }//from ww w. j a v a 2 s . c o m Thread t1 = new Thread(new MessageDispatcher()); t1.setDaemon(true); this.hub.getThreadPool().execute(t1); Thread t2 = new Thread(new Requester()); t2.setDaemon(true); this.hub.getThreadPool().execute(t2); Requester r = new Requester(); r.run(); }