List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:JobScheduler.java
private synchronized long runJobs() { long minDiff = Long.MAX_VALUE; long now = System.currentTimeMillis(); for (int i = 0; i < jobs.size();) { JobNode jn = (JobNode) jobs.elementAt(i); if (jn.executeAt.getTime() <= now) { if (tp != null) { tp.addRequest(jn.job);//w w w. ja v a 2 s . c o m } else { Thread jt = new Thread(jn.job); jt.setDaemon(false); jt.start(); } if (updateJobNode(jn) == null) { jobs.removeElementAt(i); dlock.release(); } } else { long diff = jn.executeAt.getTime() - now; minDiff = Math.min(diff, minDiff); i++; } } return minDiff; }
From source file:com.hellblazer.jackal.configuration.ThreadConfig.java
@Bean(name = "communicationsDispatchers") @Primary/*from w ww .jav a2 s . co m*/ @Autowired public ExecutorService communicationsDispatchers(Identity partitionIdentity) { final int id = partitionIdentity.id; return Executors.newCachedThreadPool(new ThreadFactory() { int count = 0; @Override public Thread newThread(Runnable target) { Thread t = new Thread(target, String.format("Communications Dispatcher[%s] for node[%s]", count++, id)); t.setDaemon(true); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error(String.format("Exception on %s", t), e); } }); return t; } }); }
From source file:com.taobao.pushit.server.listener.ConnectionNumberListener.java
public ConnectionNumberListener(int connThreshold, int ipCountThreshold, int ipCheckTaskInterval) { this.connThreshold = connThreshold; this.ipCountThreshold = ipCountThreshold; this.ipCheckTaskInterval = ipCheckTaskInterval; this.scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("connection num control thread"); t.setDaemon(true); return t; }/*from w w w .ja va2 s. c om*/ }); this.scheduler.scheduleAtFixedRate(new Runnable() { public void run() { int ipCount = ConnectionNumberListener.this.connectionIpNumMap.size(); if (ipCount >= ConnectionNumberListener.this.ipCountThreshold) { log.warn("IP, IP, IP=" + ipCount + ", =" + ConnectionNumberListener.this.ipCountThreshold); isOverflow = true; } else { isOverflow = false; } } }, this.ipCheckTaskInterval, this.ipCheckTaskInterval, TimeUnit.SECONDS); }
From source file:org.eclipse.virgo.ide.runtime.internal.core.ServerStatusPingThread.java
/** * Creates a new {@link ServerStatusPingThread} *//*w w w .ja v a 2 s .co m*/ protected ServerStatusPingThread(ServerBehaviour behaviour) { this.behaviour = behaviour; Thread t = new Thread("SpringSource dm Server Ping Thread") { @Override public void run() { ping(); } }; t.setDaemon(true); t.start(); }
From source file:dk.statsbiblioteket.util.watch.FolderWatcher.java
/** * Create a watcher for the given watchedFolder. The watcher checks for * changes, fires an event if any deletions happens, then sleeps for * pollInterval seconds before the next check. If an addition happens, * the watcher collects the file sizes, waits {@link #grace} ms, then * fires an event if the sizes haven't changes, else waits again. * * @param watchedFolder the folder to watch for changes. * @param pollInterval how often, in seconds, to check for changes. * @param grace the grace period for addition notifications. * @throws IOException if the content of the watched folder could not be * determined.//from w w w . j a va 2s . com */ public FolderWatcher(File watchedFolder, int pollInterval, int grace) throws IOException { log.debug("Creating watcher for folder '" + watchedFolder + "' with an interval of " + pollInterval + " seconds and a " + "grace period of " + grace + "ms"); this.watchedFolder = watchedFolder; this.pollInterval = pollInterval; this.grace = grace; oldContent = getContent(); Thread thread = new Thread(this); thread.setDaemon(true); // Allow the JVm to exit thread.start(); }
From source file:net.bluehornreader.service.FeedManagerService.java
/** * Just creates the leader elector and lets it take over *//*from ww w .j ava 2s . com*/ @Override public void run() { LOG.info("Starting LeaderElector ..."); leaderElector = new LeaderElector(Config.getConfig().feedManagerTicksBeforeBecomingLeader, Config.getConfig().feedManagerTickInterval); Thread t = new Thread(leaderElector); t.setDaemon(true); t.setName("FeedManagerService/" + IP); t.start(); try { t.join(); } catch (InterruptedException e) { LOG.error("Exception running LeaderElector", e); } LOG.info(String.format("FeedManagerService %s exiting", IP)); }
From source file:android.apn.androidpn.server.xmpp.XmppServer.java
/** * Stops the server./* ww w .j a v a 2 s .c o m*/ */ public void stop() { shutdownServer(); Thread shutdownThread = new ShutdownThread(); shutdownThread.setDaemon(true); shutdownThread.start(); }
From source file:$.ControllerService.java
public void setMQTTConnector(final MQTTConnector MQTTConnector) { Runnable connector = new Runnable() { public void run() { if (waitForServerStartup()) { return; }/*from w w w.j ava 2s . c om*/ ControllerService.this.mqttConnector = MQTTConnector; if (MqttConfig.getInstance().isEnabled()) { mqttConnector.connect(); } else { log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, MQTTConnector" + " not started."); } } }; Thread connectorThread = new Thread(connector); connectorThread.setDaemon(true); connectorThread.start(); }
From source file:$.MQTTConnector.java
/** * This method will initialize connection with message broker *//* ww w .j a v a 2s . co m*/ @Override public void connect() { Runnable connector = new Runnable() { public void run() { while (!isConnected()) { try { String brokerUsername = MqttConfig.getInstance().getMqttQueueUsername(); String brokerPassword = MqttConfig.getInstance().getMqttQueuePassword(); setUsernameAndPassword(brokerUsername, brokerPassword); connectToQueue(); } catch (TransportHandlerException e) { log.error("Connection to MQTT Broker at: " + mqttBrokerEndPoint + " failed", e); try { Thread.sleep(timeoutInterval); } catch (InterruptedException ex) { log.error("MQTT-Connector: Thread Sleep Interrupt Exception.", ex); } } try { subscribeToQueue(); } catch (TransportHandlerException e) { log.warn("Subscription to MQTT Broker at: " + mqttBrokerEndPoint + " failed", e); } } } }; Thread connectorThread = new Thread(connector); connectorThread.setDaemon(true); connectorThread.start(); }
From source file:$.MQTTConnector.java
/** * connection with message broker can be terminated *//*from w w w . j av a 2s . c o m*/ @Override public void disconnect() { Runnable stopConnection = new Runnable() { public void run() { while (isConnected()) { try { closeConnection(); } catch (MqttException e) { if (log.isDebugEnabled()) { log.warn("Unable to 'STOP' MQTT connection at broker at: " + mqttBrokerEndPoint); } try { Thread.sleep(timeoutInterval); } catch (InterruptedException e1) { log.error("MQTT-Terminator: Thread Sleep Interrupt Exception"); } } } } }; Thread terminatorThread = new Thread(stopConnection); terminatorThread.setDaemon(true); terminatorThread.start(); }