List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
public void handleMindForgerActiveOutlineUpload() { Thread thread = new Thread() { public void run() { try { uploadActiveOutlineToMindForger(); } catch (Exception e) { logger.error("Unable to upload active Outline to MindForger!", e); }/*from w w w . jav a 2 s . c om*/ } }; thread.setDaemon(true); thread.start(); }
From source file:edu.ku.brc.services.mapping.LocalityMapper.java
/** * Starts a thread to grab a new map. When the process succeeds * or fails, <code>callback</code> will be notified. * * @param callback the object to notify when completed *///from w ww . j av a2 s . com public void getMap(final MapperListener callback) { Thread mapGrabberThread = new Thread("Map Grabber") //$NON-NLS-1$ { @Override public void run() { try { Icon map = grabNewMap(); if (callback != null) { callback.mapReceived(map); } } catch (Exception e) { if (callback != null) { callback.exceptionOccurred(e); } } } }; mapGrabberThread.setDaemon(true); mapGrabberThread.start(); }
From source file:net.dv8tion.jda.audio.AudioConnection.java
public void ready(long timeout) { Thread readyThread = new Thread("AudioConnection Ready Guild: " + channel.getGuild().getId()) { @Override//from w w w.j a v a 2s.c o m public void run() { JDAImpl api = (JDAImpl) getJDA(); long started = System.currentTimeMillis(); boolean connectionTimeout = false; while (!webSocket.isReady() && !connectionTimeout) { if (timeout > 0 && System.currentTimeMillis() - started > timeout) { connectionTimeout = true; break; } try { Thread.sleep(10); } catch (InterruptedException e) { LOG.log(e); } } if (!connectionTimeout) { AudioConnection.this.udpSocket = webSocket.getUdpSocket(); setupSendThread(); setupReceiveThread(); api.getEventManager().handle(new AudioConnectEvent(api, AudioConnection.this.channel)); } else { webSocket.close(false, AudioWebSocket.CONNECTION_SETUP_TIMEOUT); api.getEventManager().handle(new AudioTimeoutEvent(api, AudioConnection.this.channel, timeout)); } } }; readyThread.setDaemon(true); readyThread.start(); }
From source file:org.dasein.cloud.aws.AWSCloud.java
public boolean createTags(final String service, final String[] resourceIds, final Tag... keyValuePairs) { // TODO(stas): de-async experiment boolean async = false; if (async) {// w w w . ja v a 2 s .co m hold(); Thread t = new Thread() { public void run() { try { createTags(1, service, resourceIds, keyValuePairs); } finally { release(); } } }; t.setName("Tag Setter"); t.setDaemon(true); t.start(); } else { createTags(1, service, resourceIds, keyValuePairs); } return true; }
From source file:com.linkedin.databus2.core.container.netty.ServerContainer.java
public void shutdownAsynchronously() { LOG.info("Initiating asynchronous shutdown for serving container: " + _containerStaticConfig.getId()); _controlLock.lock();/*w ww .ja v a 2s . c o m*/ try { if (_shutdown) return; if (!_shutdownRequest) { _shutdownRequest = true; _shutdownCondition.signalAll(); Thread shutdownThread = new Thread(new ShutdownRunnable(), "shutdown thread for container: " + _containerStaticConfig.getId()); shutdownThread.setDaemon(true); shutdownThread.start(); } } finally { _controlLock.unlock(); } }
From source file:com.zenkey.net.prowser.Tab.java
/************************************************************************** * Executes the specified {@link Request} and returns a new * {@link Response} object./*from w ww. ja v a2 s . co m*/ * <p> * At the end of the transaction, the <code>Request</code> argument and * <code>Response</code> result are saved as the "current" request and * response in order to provide browser functionality like * {@link #refresh() page refreshing} and * {@link #getPageSource() source viewing}. * * @param request * The <code>Request</code> object representing the page request * to be made. * @return A new <code>Response</code> object for the specified * <code>Request</code>. * @throws IllegalArgumentException * If <code>request</code> is <code>null</code>. */ private Response processRequest(Request request) { // Mark the start time for calculating the request's duration long requestStartTime = System.currentTimeMillis(); // Make sure the tab is still open if (isClosed) throw new IllegalStateException("Tab is closed"); // Validate request argument if (request == null) { history.remove(historyIndex--); throw new IllegalArgumentException("Tab request is null"); } // If defined, use the temp timeout (set in a call to stop()), else if // the Request object explictly specifies a timeout, use it, else use // the Tab's default request timeout Integer timeout; if (tempTimeout != null) { timeout = tempTimeout; tempTimeout = null; } else if (request.getTimeout() != null) timeout = request.getTimeout(); else timeout = prowser.getDefaultTimeout(); // Set up an object to run the request RequestRunnable requestRunnable = new RequestRunnable(this, request, timeout); // If timeout is not "infinite", run request in a timed thread Thread requestThread = null; if (timeout.intValue() != Request.TIMEOUT_INFINITE) { // Start the request in a different thread requestThread = new Thread(requestRunnable); requestThread.setDaemon(true); requestThread.start(); // Wait as long as the timeout for the request thread to complete try { requestThread.join(timeout); } catch (InterruptedException e) { throw new IllegalStateException("Request thread was unexpectedly interrupted"); } // If timeout occurred, stop the request thread and set resulting // values for this special case if (!requestRunnable.requestCompleted) { // Tell the request thread to stop processing the request requestRunnable.requestTimedOut = true; // Create an exception and error state for the timeout requestRunnable.exception = new TimeoutException("Tab request timed out after " + timeout + " milliseconds [" + request.getUri().toString() + "]"); requestRunnable.error = Response.ERR_TIMEOUT; requestRunnable.errorText = "Request timeout. " + requestRunnable.exception.getClass().getName() + ": " + requestRunnable.exception.getMessage(); // Specify values for response status and content requestRunnable.status = Response.STATUS_NOT_OBTAINED; requestRunnable.statusText = null; requestRunnable.statusVersion = null; requestRunnable.pageBytes = null; requestRunnable.responseCharset = null; } } // Else an "infinite" timeout means request doesn't need a timed thread else requestRunnable.run(); // Build the new response Response response = new Response(); response.setError(requestRunnable.error); response.setErrorText(requestRunnable.errorText); response.setStatus(requestRunnable.status); response.setStatusText(requestRunnable.statusText); response.setStatusVersion(requestRunnable.statusVersion); response.setPageBytes(requestRunnable.pageBytes); response.setPageCharset(requestRunnable.responseCharset); response.setPageContentType(requestRunnable.responseContentType); response.setUri(requestRunnable.uriFinal); response.setTab(this); // Save the request in the response, and vice versa response.setRequest(request); request.setResponse(response); // Save the request and response as the current request and response currentRequest = request; currentResponse = response; if (traceLevel > TRACE_OFF && requestRunnable.exception != null) { requestRunnable.exception.printStackTrace(); } // Record the request's duration in the new response response.setDuration(System.currentTimeMillis() - requestStartTime); // Return the response resulting from the request return response; }
From source file:Filter3dTest.java
/** * Exits the VM from a daemon thread. The daemon thread waits 2 seconds then * calls System.exit(0). Since the VM should exit when only daemon threads * are running, this makes sure System.exit(0) is only called if neccesary. * It's neccesary if the Java Sound system is running. *//*from w w w. ja va 2 s . c om*/ public void lazilyExit() { Thread thread = new Thread() { public void run() { // first, wait for the VM exit on its own. try { Thread.sleep(2000); } catch (InterruptedException ex) { } // system is still running, so force an exit System.exit(0); } }; thread.setDaemon(true); thread.start(); }
From source file:com.adito.server.ServerLock.java
/** * Should be called when the service starts. This checks if a service is * already running, and if not creates the lock so future instances know. * /*from w w w . j a v a 2 s. c o m*/ * @param port port the service is running on * @throws IOException */ public void start(int port) throws IOException { this.port = port; this.setup = ContextHolder.getContext().isSetupMode(); /* * Check whether there is already a listener on the port, this means we * can throw a more meaningful exception than jetty does if a server * other than Adito is already running on this port */ checkStatus(); if (locked) { if (port == 443 || port == 8443) { throw new IOException("Some other server is already running on port " + port + "." + "Most web servers will run on this port by default, so check if you have such " + "a service is installed (IIS, Apache or Tomcat for example). Either shutdown " + "and disable the conflicting server, or if you wish to run both services " + "concurrently, change the port number on which one listens."); } else { throw new IOException("Some other server is already running on port " + port + "." + "Check which other services you have enabled that may be causing " + "this conflict. Then, either disable the service, change the port on " + "which it is listening or change the port on which this server listens."); } } // PrintWriter pw = new PrintWriter(new FileOutputStream(lockFile)); pw.println(ContextHolder.getContext().isSetupMode() + ":" + port); pw.flush(); pw.close(); started = true; lastLockChange = lockFile.lastModified(); /* Start watching the lock file, if it disappears then shut down the * server */ Thread t = new Thread("ServerLockMonitor") { public void run() { while (true) { try { Thread.sleep(5000); if (lastLockChange != lockFile.lastModified()) { lastLockChange = lockFile.lastModified(); if (log.isDebugEnabled()) log.debug("Lock file changed, examining"); InputStream in = null; try { in = new FileInputStream(lockFile); ; BufferedReader br = new BufferedReader(new InputStreamReader(in)); String s = br.readLine(); Util.closeStream(in); // close so we can delete if ("shutdown".equals(s)) { ContextHolder.getContext().shutdown(false); break; } else if ("restart".equals(s)) { ContextHolder.getContext().shutdown(true); break; } } catch (IOException ioe) { Util.closeStream(in); throw ioe; } } } catch (Exception e) { } } } }; t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); t.start(); }
From source file:com.sslexplorer.server.ServerLock.java
/** * Should be called when the service starts. This checks if a service is * already running, and if not creates the lock so future instances know. * /*from w w w. j av a2 s . c o m*/ * @param port port the service is running on * @throws IOException */ public void start(int port) throws IOException { this.port = port; this.setup = ContextHolder.getContext().isSetupMode(); /* * Check whether there is already a listener on the port, this means we * can throw a more meaningful exception than jetty does if a server * other than SSL-Explorer is already running on this port */ checkStatus(); if (locked) { if (port == 443 || port == 8443) { throw new IOException("Some other server is already running on port " + port + "." + "Most web servers will run on this port by default, so check if you have such " + "a service is installed (IIS, Apache or Tomcat for example). Either shutdown " + "and disable the conflicting server, or if you wish to run both services " + "concurrently, change the port number on which one listens."); } else { throw new IOException("Some other server is already running on port " + port + "." + "Check which other services you have enabled that may be causing " + "this conflict. Then, either disable the service, change the port on " + "which it is listening or change the port on which this server listens."); } } // PrintWriter pw = new PrintWriter(new FileOutputStream(lockFile)); pw.println(ContextHolder.getContext().isSetupMode() + ":" + port); pw.flush(); pw.close(); started = true; lastLockChange = lockFile.lastModified(); /* Start watching the lock file, if it disappears then shut down the * server */ Thread t = new Thread("ServerLockMonitor") { public void run() { while (true) { try { Thread.sleep(5000); if (lastLockChange != lockFile.lastModified()) { lastLockChange = lockFile.lastModified(); if (log.isDebugEnabled()) log.debug("Lock file changed, examining"); InputStream in = null; try { in = new FileInputStream(lockFile); ; BufferedReader br = new BufferedReader(new InputStreamReader(in)); String s = br.readLine(); Util.closeStream(in); // close so we can delete if ("shutdown".equals(s)) { ContextHolder.getContext().shutdown(false); break; } else if ("restart".equals(s)) { ContextHolder.getContext().shutdown(true); break; } } catch (IOException ioe) { Util.closeStream(in); throw ioe; } } } catch (Exception e) { } } } }; t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); t.start(); }