Example usage for java.lang Thread setDaemon

List of usage examples for java.lang Thread setDaemon

Introduction

In this page you can find the example usage for java.lang Thread setDaemon.

Prototype

public final void setDaemon(boolean on) 

Source Link

Document

Marks this thread as either a #isDaemon daemon thread or a user thread.

Usage

From source file:Main.java

public static ThreadFactory daemonThreadFactory(final String name) {
    return new ThreadFactory() {
        private int nextId = 0;

        public synchronized Thread newThread(Runnable r) {
            Thread thread = new Thread(r, name + "-" + (nextId++));
            thread.setDaemon(true);
            return thread;
        }/*w  ww .  j  av a  2s  .  c o m*/
    };
}

From source file:Main.java

public static ExecutorService createEventsOrderedDeliveryExecutor() {
    return Executors.newSingleThreadExecutor(new ThreadFactory() {
        private AtomicInteger cnt = new AtomicInteger(0);

        @Override/*from  w  w w.ja  v a 2  s .c o m*/
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "Ordered Events Thread-" + cnt.incrementAndGet());
            t.setDaemon(true);
            // XXX perhaps set uncaught exception handler here according to resilience strategy
            return t;
        }
    });
}

From source file:Main.java

public static ExecutorService createEventsUnorderedDeliveryExecutor() {
    return Executors.newCachedThreadPool(new ThreadFactory() {
        private AtomicInteger cnt = new AtomicInteger(0);

        @Override//from  w  ww  .j  av a  2 s  . com
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "Unordered Events Thread-" + cnt.incrementAndGet());
            t.setDaemon(true);
            // XXX perhaps set uncaught exception handler here according to resilience strategy
            return t;
        }
    });
}

From source file:Main.java

public static ThreadPoolExecutor createExecutor(final String name, int count, int keepAlive,
        final boolean isDaemon) {
    ThreadPoolExecutor exe = new ThreadPoolExecutor(count, count, keepAlive, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
                private int threadNum = 1;

                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r, name + (threadNum++));
                    t.setDaemon(isDaemon);
                    return t;
                }/*  ww w .  j a  v  a2 s.  c  o m*/

            });

    // if (keepAlive > 0) {
    // // FIXME JDK 1.7 ?
    // if (SystemUtils.IS_JAVA_1_5 == false) {
    // try {
    // exe.allowCoreThreadTimeOut(true);
    // } catch(Throwable t) { }
    // }
    // }

    return exe;
}

From source file:Main.java

public static ScheduledExecutorService createStatisticsExecutor() {
    return Executors.newScheduledThreadPool(Integer.getInteger(ORG_EHCACHE_STATISTICS_EXECUTOR_POOL_SIZE, 1),
            new ThreadFactory() {
                private AtomicInteger cnt = new AtomicInteger(0);

                @Override/*from w w  w. ja v a2s .  c om*/
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r, "Statistics Thread-" + cnt.incrementAndGet());
                    t.setDaemon(true);
                    return t;
                }
            });
}

From source file:TimeoutController.java

/**
 * Executes <code>task</code> in a new deamon Thread and waits for the timeout.
 * @param task The task to execute/*from  w ww.j a  va2  s.c o  m*/
 * @param timeout The timeout in milliseconds. 0 means to wait forever.
 * @throws TimeoutException if the timeout passes and the thread does not return.
 */
public static void execute(Runnable task, long timeout) throws TimeoutException {
    Thread t = new Thread(task, "Timeout guard");
    t.setDaemon(true);
    execute(t, timeout);
}

From source file:org.pepstock.jem.node.HttpsInternalSubmitter.java

/**
 * Starts the HTTP listener, setting the handlers and SSL factory.
 * //w  w w  .j a v  a  2  s.c o m
 * @param port port to stay in listening mode
 * @throws ConfigurationException if any errors occurs
 */
public static void start(int port) throws ConfigurationException {
    // Set up the HTTP protocol processor
    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("Jem/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    // Set up request handlers
    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register(SubmitHandler.DEFAULT_ACTION, new SubmitHandler());

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);
    try {
        // sets HTTPS ALWAYS, take a SSL server socket factory
        SSLServerSocketFactory sf = KeyStoreUtil.getSSLServerSocketFactory();
        // creates thread and starts it.
        Thread t = new RequestListener(port, httpService, sf);
        t.setDaemon(false);
        t.start();
    } catch (Exception e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}

From source file:Main.java

public static Runnable excAsync(final Runnable runnable, boolean isDeamon) {
    Thread thread = new Thread() {
        @Override// w  w w  .  j av a 2 s . c  o m
        public void run() {
            runnable.run();
        }
    };
    thread.setDaemon(isDeamon);
    thread.start();

    return runnable;
}

From source file:Main.java

public static ThreadFactory createThreadFactory(final String prefix) {
    return new ThreadFactory() {
        private AtomicInteger size = new AtomicInteger();

        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r);
            thread.setName(prefix + size.incrementAndGet());
            if (thread.isDaemon()) {
                thread.setDaemon(false);
            }/*  ww w.j av a2 s .c  o  m*/
            return thread;
        }
    };
}

From source file:com.vaadin.tools.ReportUsage.java

public static FutureTask<Void> checkForUpdatesInBackgroundThread() {
    FutureTask<Void> task = new FutureTask<>(new Callable<Void>() {
        @Override/*from  w  w  w .  ja  v a  2s.c  om*/
        public Void call() throws Exception {
            ReportUsage.report();
            return null;
        }
    });
    Thread checkerThread = new Thread(task, "Vaadin Update Checker");
    checkerThread.setDaemon(true);
    checkerThread.start();
    return task;
}