List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:com.cisco.oss.foundation.message.RabbitMQMessagingFactory.java
static void triggerReconnectThread() { if (IS_RECONNECT_THREAD_RUNNING.compareAndSet(false, true)) { Thread reconnectThread = new Thread(new Runnable() { @Override/*from w w w .j av a 2 s .co m*/ public void run() { while (!IS_CONNECTED.get()) { try { connect(); } catch (Exception e) { LOGGER.trace("reconnect failed: " + e); try { Thread.sleep(ConfigurationFactory.getConfiguration() .getInt("service.rabbitmq.attachRetryDelay", 10000)); } catch (InterruptedException e1) { LOGGER.trace("thread interrupted!!!", e1); } } } IS_RECONNECT_THREAD_RUNNING.set(false); } }, "RabbitMQ-Reconnect"); reconnectThread.setDaemon(false); reconnectThread.start(); } }
From source file:de.xwic.appkit.core.cluster.impl.InboundConnectionHandler.java
@Override public void run() { ServerSocket srvSocket;/* ww w.j a v a 2 s. c o m*/ try { srvSocket = new ServerSocket(port); } catch (IOException e) { log.error("Can not open server socket", e); return; // exit } int conHandlerCount = 0; int errCount = 0; long lastErr = 0; while (true) { try { Socket socket = srvSocket.accept(); log.debug("Accepted connection from " + socket.getInetAddress().getHostAddress()); ClientHandler ch = new ClientHandler(cluster, socket); Thread t = new Thread(ch, "ConnectionHandler-" + socket.getInetAddress().getHostAddress() + "-" + conHandlerCount++); t.setDaemon(true); // launch as a Deamon t.start(); } catch (IOException e) { log.error("Error accepting incoming connection...", e); if ((System.currentTimeMillis() - lastErr) < 3000) { // the last error was just 3 seconds ago errCount++; if (errCount > 100) { log.error("More than 100 errors occured within the last 3 seconds. Giving up."); break; // break the loop } } else { errCount = 0; } lastErr = System.currentTimeMillis(); } } }
From source file:com.android.unit_tests.TestHttpServer.java
public void start() { if (this.listener != null) { throw new IllegalStateException("Listener already running"); }/*from w w w . j a v a 2 s . c o m*/ this.listener = new Thread(new Runnable() { public void run() { while (!shutdown && !Thread.interrupted()) { try { // Set up HTTP connection HttpServerConnection conn = acceptConnection(); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, connStrategy, responseFactory); httpService.setParams(params); httpService.setExpectationVerifier(expectationVerifier); httpService.setHandlerResolver(reqistry); // Start worker thread Thread t = new WorkerThread(httpService, conn); t.setDaemon(true); t.start(); } catch (InterruptedIOException ex) { break; } catch (IOException e) { break; } } } }); this.listener.start(); }
From source file:com.icesoft.util.ThreadFactory.java
public Thread newThread(final Runnable runnable) { Thread _thread; synchronized (lock) { _thread = new Thread(runnable, prefix + " [" + ++counter + "]"); }/*from ww w . ja va 2 s . c o m*/ _thread.setDaemon(daemon); try { /* * We attempt to set the context class loader because some J2EE * containers don't seem to set this properly, which leads to * important classes not being found. However, other J2EE containers * see this as a security violation. */ _thread.setContextClassLoader(runnable.getClass().getClassLoader()); } catch (SecurityException exception) { /* * If the current security policy does not allow this, we have to * hope that the appropriate class loader settings were transferred * to this new thread. */ if (LOG.isTraceEnabled()) { LOG.trace("Setting the context class loader is not permitted.", exception); } } if (LOG.isDebugEnabled()) { LOG.debug("New thread: " + _thread.getName()); } return _thread; }
From source file:io.github.thefishlive.updater.HttpServer.java
public void run() { try {/*from w w w . j a v a 2 s. com*/ int port = GitUpdater.port; // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("GitUpdater/1.0-SNAPSHOT")).add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new ResponceHandler()); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; if (port == 8443) { // Initialize SSL context ClassLoader cl = getClass().getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { System.out.println("Keystore not found"); System.exit(1); } KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); sf = sslcontext.getServerSocketFactory(); } try { Thread t = new RequestListenerThread(port, httpService, sf); t.setDaemon(false); t.start(); } catch (BindException ex) { System.out.println("Error binding to port " + port); System.out.println("Perhaps another server is running on that port"); return; } catch (IOException ex) { ex.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.dianping.resource.io.util.CustomizableThreadCreator.java
/** * Template method for the creation of a new {@link Thread}. * <p>The default implementation creates a new Thread for the given * {@link Runnable}, applying an appropriate thread name. * @param runnable the Runnable to execute * @see #nextThreadName()//w ww .j a v a 2 s. c om */ public Thread createThread(Runnable runnable) { Thread thread = new Thread(getThreadGroup(), runnable, nextThreadName()); thread.setPriority(getThreadPriority()); thread.setDaemon(isDaemon()); return thread; }
From source file:com.mnt.base.stream.comm.PacketProcessorManager.java
private void initProcessorThreads(int maxThreads) { processorThreadGroup = new ThreadGroup(PacketProcessorManager.class.getSimpleName()); processorThreadGroup.setDaemon(true); runningFlag = true;//from w w w. j a v a 2s .c om Thread t = null; for (int i = 0; i < maxThreads; i++) { t = new Thread(processorThreadGroup, this); t.setDaemon(true); t.start(); } }
From source file:com.devoteam.srit.xmlloader.http.test.HttpLoaderServer.java
public HttpLoaderServer(String hostname, int port) { this.port = port; this.hostname = hostname; try {/* w w w. java 2 s . c om*/ Thread server = new RequestListenerServerThread(port); server.setDaemon(false); server.start(); } catch (Exception e) { /*e.printStackTrace();*/} }
From source file:com.betfair.testing.utils.cougar.manager.LogTailer.java
public void awaitStart() throws InterruptedException { Thread t = new Thread(tailer, getClass().getSimpleName()); t.setDaemon(true); t.start();/*from w w w . j a v a 2 s . com*/ startupLatch.await(); }
From source file:com.mnt.base.stream.comm.PacketProcessorManager.java
public void increaseProcessorThreads(int maxThreads) { if (runningFlag && enablePacketCacheQueue) { Thread t = null; for (int i = 0; i < maxThreads; i++) { t = new Thread(processorThreadGroup, this); t.setDaemon(true); t.start();//from w w w . j a v a 2 s . co m } } }