List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:org.madsonic.service.PodcastService.java
public PodcastService() { ThreadFactory threadFactory = new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; }/*from ww w. j ava 2 s . c o m*/ }; refreshExecutor = Executors.newFixedThreadPool(5, threadFactory); downloadExecutor = Executors.newFixedThreadPool(4, threadFactory); //settingsService.getPodcastEpisodeDownloadLimit() scheduledExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory); }
From source file:gds.net.TFTPServer.java
public void run() { try {//from w ww . ja v a 2 s.c om while (!shutdownServer) { TFTPPacket tftpPacket; tftpPacket = serverTftp_.receive(); TFTPTransfer tt = new TFTPTransfer(tftpPacket); synchronized (transfers_) { transfers_.add(tt); } Thread thread = new Thread(tt); thread.setDaemon(true); thread.start(); } } catch (Exception e) { if (!shutdownServer) { serverException = e; logError_.println("Unexpected Error in TFTP Server - Server shut down! + " + e); } } finally { shutdownServer = true; // set this to true, so the launching thread can check to see if it started. if (serverTftp_ != null && serverTftp_.isOpen()) { serverTftp_.close(); } } }
From source file:com.web.searchlocal.flashpaper.thread.Covnert2SwfTask.java
/** * /* w ww .ja v a2 s .c o m*/ */ public void excute() { String tmpOutFile = outFile.getPath().concat(File.separator) .concat(inFile.getName().replaceAll("[.]{1}.*$", ".swf")); List<String> commandArray = new ArrayList<String>(); commandArray.add(defaultCommand); commandArray.add(inFile.getPath()); commandArray.add("-o"); commandArray.add(tmpOutFile); ProcessBuilder pbObj = new ProcessBuilder(); pbObj.command(commandArray); pbObj.directory(outFile); pbObj.redirectErrorStream(true); try { Process proObj = pbObj.start(); final InputStream ins = proObj.getInputStream(); final ByteBuffer byteBuffer = ByteBuffer.allocate(1024); Thread th = new Thread() { public void run() { ReadableByteChannel rbcObj = Channels.newChannel(ins); try { while (rbcObj.read(byteBuffer) != -1) { byteBuffer.flip(); logger.info(java.nio.charset.Charset.defaultCharset().decode(byteBuffer)); byteBuffer.clear(); } } catch (IOException e) { logger.error(e); } } }; th.setDaemon(true); th.start(); try { proObj.waitFor(); logger.error("??." + tmpOutFile); } catch (InterruptedException e) { logger.error(e); } } catch (IOException e) { logger.error(e); } }
From source file:org.sakaiproject.event.impl.BaseLearningResourceStoreService.java
public void registerStatement(LRS_Statement statement, String origin) { if (statement == null) { log.error("LRS registerStatement call INVALID, statement is null and must not be"); //throw new IllegalArgumentException("statement must be set"); } else if (isEnabled()) { if (providers == null || providers.isEmpty()) { if (noProvidersWarningTS < (System.currentTimeMillis() - 86400000)) { // check if we already warned in the last 24 hours noProvidersWarningTS = System.currentTimeMillis(); log.warn("LRS statement from (" + origin + ") skipped because there are no providers to process it: " + statement); }//from w w w. j av a 2 s.com } else { // filter out certain tools and statement origins boolean skip = false; if (originFilters != null && !originFilters.isEmpty()) { origin = StringUtils.trimToNull(origin); if (origin != null && originFilters.contains(origin)) { if (log.isDebugEnabled()) log.debug("LRS statement skipped because origin (" + origin + ") matches the originFilter"); skip = true; } } if (!skip) { // validate the statement boolean valid = false; if (statement.isPopulated() && statement.getActor() != null && statement.getVerb() != null && statement.getObject() != null) { valid = true; } else if (statement.getRawMap() != null && !statement.getRawMap().isEmpty()) { valid = true; } else if (statement.getRawJSON() != null && !StringUtils.isNotBlank(statement.getRawJSON())) { valid = true; } if (valid) { // process this statement if (log.isDebugEnabled()) log.debug( "LRS statement being processed, origin=" + origin + ", statement=" + statement); for (LearningResourceStoreProvider lrsp : providers.values()) { // run the statement processing in a new thread String threadName = "LRS_" + lrsp.getID(); Thread t = new Thread(new RunStatementThread(lrsp, statement), threadName); // each provider has it's own thread t.setDaemon(true); // allow this thread to be killed when the JVM is shutdown t.start(); } } else { log.warn("Invalid statment registered, statement will not be processed: " + statement); } } else { if (log.isDebugEnabled()) log.debug("LRS statement being skipped, origin=" + origin + ", statement=" + statement); } } } }
From source file:com.intuit.tank.standalone.agent.StandaloneAgentStartup.java
private void startPinger() { Thread t = new Thread(new Runnable() { public void run() { while (true) { try { sendAvailability();/*from w w w .j a v a 2 s . co m*/ } catch (Exception e1) { LOG.warn("Error sending Availability: " + e1, e1); } try { Thread.sleep(PING_TIME); } catch (InterruptedException e) { LOG.warn("Interrupted during sleep.", e); } } } }); t.setDaemon(true); t.start(); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorServ.java
/** Works like MetricsUpdates, except for Price Chart updates */ private void startPriceChartUpdateThread() { priceChartUpdates = new Vector(); Runnable updater = new Runnable() { public void run() { try { while (!priceChartDone) { PriceChartUpdate pupdate = getNextUpdate(); if (pupdate.sessionId == -1) { log.debug("Shutting down auxiliary price chart update thread"); break; }/* w w w .ja va2 s.c om*/ Vector monitors = getMonitors(pupdate.sessionId); if (monitors == null) { log.warn("Cannot update MonitorTransmitters with price chart information for session " + pupdate.sessionId + " -- that session does not exist!"); continue; } for (int i = 0; i < monitors.size(); i++) { MonitorTransmitter ui = (MonitorTransmitter) monitors.get(i); try { ui.updatePriceChart(pupdate.security, pupdate.time, pupdate.price); } catch (MonitorDisconnectedException e) { log.error( "Failed to establish connection with MonitorTransmitter -- disconnecting from failed monitor"); disconnectMonitor(pupdate.sessionId, ui); } } } } catch (Exception e) { log.error("MonitorServ failed to update admin screen with price chart information", e); } } private synchronized PriceChartUpdate getNextUpdate() throws InterruptedException { try { if (priceChartDone) { log.info("priceChartUpdate ending... returning from getNextUpdate()..."); return new PriceChartUpdate(0, "0", 0.f, 0.f); } if (!priceChartUpdates.isEmpty() && priceChartUpdates.size() > 0) return (PriceChartUpdate) priceChartUpdates.remove(0); else wait(1000); return getNextUpdate(); } catch (Exception e) { log.debug("Price chart updates lost synchronization -- resynchronizing"); return getNextUpdate(); } } }; Thread updateThr = new Thread(updater); updateThr.setDaemon(true); updateThr.start(); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorServ.java
/** Works like MetricsUpdates, except for offer backlog updates. These updates tell the server administrator * how many offers are waiting to be processed. When this number reaches some critical amount, the server * should temporarily stop accepting offers */ private void startOfferBacklogThread() { offerBacklogUpdates = new Vector(); Runnable updater = new Runnable() { public void run() { try { while (!offerBacklogDone) { OfferBacklogUpdate update = getNextUpdate(); if (update.backlog == -1) { log.debug("Shutting down auxiliary offer backlog update thread"); break; }/*w w w. java 2 s . c om*/ Enumeration sessionIds = sessionMonitors.keys(); while (sessionIds.hasMoreElements()) { Integer key = (Integer) sessionIds.nextElement(); Vector monitors = (Vector) sessionMonitors.get(key); for (int i = 0; i < monitors.size(); i++) { MonitorTransmitter ui = (MonitorTransmitter) monitors.get(i); try { ui.setOfferBacklog(update.backlog, update.rejecting); } catch (MonitorDisconnectedException e) { log.error( "Failed to establish connection with MonitorTransmitter -- disconnecting from failed monitor"); disconnectMonitor(key.intValue(), ui); } } } } } catch (Exception e) { log.error("MonitorServ failed to update admin screen with offer backlog information", e); } } private synchronized OfferBacklogUpdate getNextUpdate() throws InterruptedException { try { if (offerBacklogDone) { log.info("offerBacklogUpdate ending... returning from getNextUpdate()..."); return new OfferBacklogUpdate(0, false); } if (!offerBacklogUpdates.isEmpty() && offerBacklogUpdates.size() > 0) return (OfferBacklogUpdate) offerBacklogUpdates.remove(0); else wait(1000); return getNextUpdate(); } catch (Exception e) { log.debug("Offer backlog updates lost synchronization -- resynchronizing"); return getNextUpdate(); } } }; Thread updateThr = new Thread(updater); updateThr.setDaemon(true); updateThr.start(); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorServ.java
/** Works like MetricsUpdates, except for num offers updates */ private void startNumOffersUpdateThread() { numOffersUpdates = new Vector(); Runnable updater = new Runnable() { public void run() { try { while (!numOffersDone) { NumOffersUpdate update = getNextUpdate(); if (update.sessionId == -1) { log.debug("Shutting down auxiliary num offers update thread"); break; }/*from w w w .j a va 2 s. c om*/ Vector monitors = getMonitors(update.sessionId); if (monitors == null) { log.warn("Cannot update MonitorTransmitters with num offers information for session " + update.sessionId + " -- that session does not exist!"); continue; } for (int i = 0; i < monitors.size(); i++) { MonitorTransmitter ui = (MonitorTransmitter) monitors.get(i); try { ui.updateNumOffers(update.client, update.numOffers); } catch (MonitorDisconnectedException e) { log.error( "Failed to establish connection with MonitorTransmitter -- disconnecting from failed monitor"); disconnectMonitor(update.sessionId, ui); } } } } catch (Exception e) { log.error("MonitorServ failed to update admin screen with num offers information", e); } } private synchronized NumOffersUpdate getNextUpdate() throws InterruptedException { try { if (numOffersDone) { log.info("numOffersUpdate ending... returning from getNextUpdate()..."); return new NumOffersUpdate(0, 0, 0); } if (!numOffersUpdates.isEmpty() && numOffersUpdates.size() > 0) return (NumOffersUpdate) numOffersUpdates.remove(0); else wait(1000); return getNextUpdate(); } catch (Exception e) { log.debug("Num offers updates lost synchronization -- resynchronizing"); return getNextUpdate(); } } }; Thread updateThr = new Thread(updater); updateThr.setDaemon(true); updateThr.start(); }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorServ.java
/** Start a thread that continually checks for new metrics updates and sends them to * the server admin screen. This thread is needed so that calls to the UI, which are * slow remote calls, do not prolong transaction timing so that transactions can * release market locks ASAP. The dispatcher can add updates to the metricsUpdates * queue *///from w ww. j a v a2s . com private void startMetricsUpdateThread() { metricsUpdates = new Vector(); Runnable updater = new Runnable() { public void run() { try { while (!metricsUpdateDone) { MetricsUpdate update = getNextUpdate(); if (update.sessionId == -1) { log.debug("Shutting down auxiliary metrics update thread"); break; } Vector monitors = getMonitors(update.sessionId); if (monitors == null) { log.warn("Cannot update MonitorTransmitters with metrics information for session " + update.sessionId + " -- that session does not exist!"); continue; } for (int i = 0; i < monitors.size(); i++) { MonitorTransmitter ui = (MonitorTransmitter) monitors.get(i); try { ui.updateMetrics(update.iterations, update.numTrans, update.average); } catch (MonitorDisconnectedException e) { log.error( "Failed to establish connection with MonitorTransmitter -- disconnecting from failed monitor"); disconnectMonitor(update.sessionId, ui); } } } } catch (Exception e) { log.error("MonitorServ failed to update admin screen with metrics information", e); } } private synchronized MetricsUpdate getNextUpdate() throws InterruptedException { try { if (metricsUpdateDone) { log.info("metricsUpdate ending... returning from getNextUpdate()..."); return new MetricsUpdate(0, 0, 0, 0.f); } if (!metricsUpdates.isEmpty() && metricsUpdates.size() > 0) return (MetricsUpdate) metricsUpdates.remove(0); else wait(1000); return getNextUpdate(); } catch (Exception e) { log.debug("Metrics updates lost synchronization -- resynchronizing"); return getNextUpdate(); } } }; Thread updateThr = new Thread(updater); updateThr.setDaemon(true); updateThr.start(); }
From source file:com.netflix.iep.http.RxHttp.java
/** * Setup the background tasks for cleaning up connections. *//*w ww. j a v a2 s .co m*/ @PostConstruct public void start() { LOGGER.info("starting up backround cleanup threads"); executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r, "spectator-rxhttp-" + NEXT_THREAD_ID.getAndIncrement()); t.setDaemon(true); return t; } }); Runnable task = new Runnable() { @Override public void run() { try { LOGGER.debug("executing cleanup for {} clients", clients.size()); for (Map.Entry<Server, HttpClient<ByteBuf, ByteBuf>> entry : clients.entrySet()) { final Server s = entry.getKey(); if (s.isRegistered() && !serverRegistry.isStillAvailable(s)) { LOGGER.debug("cleaning up client for {}", s); clients.remove(s); entry.getValue().shutdown(); } } LOGGER.debug("cleanup complete with {} clients remaining", clients.size()); } catch (Exception e) { LOGGER.warn("connection cleanup task failed", e); } } }; final long cleanupFreq = Spectator.config().getLong("spectator.http.cleanupFrequency", 60); executor.scheduleWithFixedDelay(task, 0L, cleanupFreq, TimeUnit.SECONDS); }