List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:Httpd.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Please specify document root directory"); System.exit(1);// w w w . ja va2 s . com } Thread t = new RequestListenerThread(8088, args[0]); t.setDaemon(false); t.start(); }
From source file:httpserver.ElementalHttpServer.java
public static void main(String[] args) throws Exception { // Clay code, adding arguments to simulate command line execution args = new String[2]; args[0] = "C://Users/Clay/Documents"; args[1] = "80"; if (args.length < 1) { System.err.println("Please specify document root directory"); System.exit(1);//from w w w .j a va 2s .c om } // Document root directory String docRoot = args[0]; // Setting up port, if port was specified, then use that one int port = 8080; if (args.length >= 2) { port = Integer.parseInt(args[1]); } // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new HttpFileHandler(docRoot)); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; if (port == 8443) { // Initialize SSL context ClassLoader cl = ElementalHttpServer.class.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(); } Thread t = new RequestListenerThread(port, httpService, sf); t.setDaemon(false); t.start(); }
From source file:io.aos.protocol.http.httpcommon.ElementalReverseProxy.java
public static void main(String... args) throws Exception { if (args.length < 1) { System.err.println("Please specified target hostname and port"); System.exit(1);/*from w w w . j av a2 s . co m*/ } String hostname = args[0]; int port = 80; if (args.length > 1) { port = Integer.parseInt(args[1]); } HttpHost target = new HttpHost(hostname, port); Thread t = new RequestListenerThread(8888, target); t.setDaemon(false); t.start(); }
From source file:com.github.rnewson.couchdb.lucene.Index.java
public static void main(String[] args) throws Exception { Utils.LOG.info("indexer started."); final Indexer indexer = new Indexer(FSDirectory.getDirectory(Config.INDEX_DIR)); final Thread thread = new Thread(indexer, "index"); thread.setDaemon(true); thread.start();//from w w w .ja v a 2 s . com final Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { final String line = scanner.nextLine(); final JSONObject obj = JSONObject.fromObject(line); if (obj.has("type") && obj.has("db")) { indexer.setStale(true); } } Utils.LOG.info("indexer stopped."); }
From source file:za.co.taung.httpdotserver.main.HttpDotServer.java
public static void main(String[] args) throws Exception { LOG.info("Initialise server"); // The parameter is the Port to listen on. Default is 8080. int port = 8080; if (args.length >= 1) { port = Integer.parseInt(args[0]); }/*ww w . j ava 2 s.c o m*/ // Set up the HTTP protocol processor. HttpProcessor httpProcessor = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("HttpDotServer/1.1")).add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Set up request handler. This is the method that generates SVG. UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new Dot2SVGHandler()); // Set up the HTTP service. HttpService httpService = new HttpService(httpProcessor, reqistry); // Set up SSL if listening on 8443 for https. SSLServerSocketFactory serverSocketFactory = null; if (port == 8443) { // Get the location of the keystore secrets. ClassLoader cl = HttpDotServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { LOG.error("Keystore not found"); System.exit(1); } // Load the secret into a keystore and manage the key material. 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(); // Prepare the socket factory for use by the RequestListenerThread. SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); serverSocketFactory = sslcontext.getServerSocketFactory(); } LOG.debug("Start the RequestListenerThread"); Thread thread = new RequestListenerThread(port, httpService, serverSocketFactory); thread.setDaemon(false); thread.start(); }
From source file:httpscheduler.HttpScheduler.java
/** * @param args the command line arguments * @throws java.lang.Exception/* w w w . j a va2 s .c o m*/ */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Invalid command line parameters for worker"); System.exit(-1); } int fixedExecutorSize = 4; //Creating fixed size executor ThreadPoolExecutor taskCommExecutor = new ThreadPoolExecutor(fixedExecutorSize, fixedExecutorSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); // Used for late binding JobMap jobMap = new JobMap(); // Set port number int port = Integer.parseInt(args[0]); // Set worker mode String mode = args[1].substring(2); // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); // Different handlers for late binding and generic cases if (mode.equals("late")) reqistry.register("*", new LateBindingRequestHandler(taskCommExecutor, jobMap)); else reqistry.register("*", new GenericRequestHandler(taskCommExecutor, mode)); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; // create a thread to listen for possible client available connections Thread t; if (mode.equals("late")) t = new LateBindingRequestListenerThread(port, httpService, sf); else t = new GenericRequestListenerThread(port, httpService, sf); System.out.println("Request Listener Thread created"); t.setDaemon(false); t.start(); // main thread should wait for the listener to exit before shutdown the // task executor pool t.join(); // shutdown task executor pool and wait for any taskCommExecutor thread // still running taskCommExecutor.shutdown(); while (!taskCommExecutor.isTerminated()) { } System.out.println("Finished all task communication executor threads"); System.out.println("Finished all tasks"); }
From source file:cache.reverseproxy.CacheableServicesReverseProxy.java
public static void main(final String[] args) throws Exception { int port = 8888; if (args.length > 0) { try {//from w w w . ja v a 2 s. c o m port = Integer.parseInt(args[0]); } catch (Exception e) { System.err.println("->Invalid Port!!"); } } final Thread t = new RequestListenerThread(port); t.setDaemon(false); t.start(); }
From source file:thrift.Httpd.java
public static void main(String[] args) throws Exception { if (args.length < 1) { logger.info("No root directory specified. Using working directory."); args = new String[1]; args[0] = "."; }//w ww. ja v a 2 s . c o m Thread t = new RequestListenerThread(8088, args[0]); t.setDaemon(false); t.start(); }
From source file:ObjectFIFOTest.java
public static void main(String[] args) { final ObjectFIFO fifo = new ObjectFIFO(5); Runnable fullCheckRunnable = new Runnable() { public void run() { fullCheck(fifo);//from w w w . j a v a2 s.com } }; Thread fullCheckThread = new Thread(fullCheckRunnable, "fchk"); fullCheckThread.setPriority(9); fullCheckThread.setDaemon(true); // die automatically fullCheckThread.start(); Runnable emptyCheckRunnable = new Runnable() { public void run() { emptyCheck(fifo); } }; Thread emptyCheckThread = new Thread(emptyCheckRunnable, "echk"); emptyCheckThread.setPriority(8); emptyCheckThread.setDaemon(true); // die automatically emptyCheckThread.start(); Runnable consumerRunnable = new Runnable() { public void run() { consumer(fifo); } }; Thread consumerThread = new Thread(consumerRunnable, "cons"); consumerThread.setPriority(7); consumerThread.start(); Runnable producerRunnable = new Runnable() { public void run() { producer(fifo); } }; Thread producerThread = new Thread(producerRunnable, "prod"); producerThread.setPriority(6); producerThread.start(); }
From source file:javarestart.JavaRestartLauncher.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println("Usage: <URL> {<MainClass>}"); return;/*from w w w. j a v a 2 s. co m*/ } if (args[0].equals("fork")) { String[] args2 = new String[args.length - 1]; for (int i = 0; i < args.length - 1; i++) { args2[i] = args[i + 1]; } fork(args2); return; } AppClassloader loader = new AppClassloader(args[0]); Thread.currentThread().setContextClassLoader(loader); String main; JSONObject obj = getJSON(args[0]); if (args.length < 2) { main = (String) obj.get("main"); } else { main = args[1]; } String splash = (String) obj.get("splash"); if (splash != null) { SplashScreen scr = SplashScreen.getSplashScreen(); if (scr != null) { URL url = loader.getResource(splash); scr.setImageURL(url); } } //auto close splash after 45 seconds Thread splashClose = new Thread() { @Override public void run() { try { sleep(45000); } catch (InterruptedException e) { } SplashScreen scr = SplashScreen.getSplashScreen(); if ((scr != null) && (scr.isVisible())) { scr.close(); } } }; splashClose.setDaemon(true); splashClose.start(); Class mainClass = loader.loadClass(main); Method mainMethod = mainClass.getMethod("main", String[].class); mainMethod.setAccessible(true); mainMethod.invoke(null, new Object[] { new String[0] }); }