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:com.flexive.testRunner.FxTestRunner.java

/**
 * Runs tests - this is a "fire and forget" function, callers have to make sure to not call this more than once!
 *
 * @param callback   the callback for results
 * @param outputPath test report output path
 *//*from ww  w .  j ava2 s  . c  om*/
public static void runTests(FxTestRunnerCallback callback, String outputPath) {
    if (FxTestRunnerThread.isTestInProgress()) {
        LOG.error("A test is currently running. Tried to start another run!");
        return;
    }
    Thread t = new FxTestRunnerThread(callback, outputPath);
    t.setDaemon(true);
    if (callback != null)
        callback.setRunning(true);
    t.start();
}

From source file:functionaltests2.SchedulerCommandLine.java

/**
 * Start a Scheduler and Resource Manager.
 *//*from   ww  w.j a va 2s .  c o  m*/
public static void startSchedulerCmdLine(boolean restart, File proactiveConf) throws Exception {

    File schedHome = new File(System.getProperty("pa.scheduler.home")).getCanonicalFile();
    File rmHome = new File(System.getProperty("pa.rm.home")).getCanonicalFile();
    if (proactiveConf != null) {
        FileUtils.copyFile(proactiveConf,
                new File(schedHome, "config" + fs + "proactive" + fs + "ProActiveConfiguration.xml"));
    }

    System.out.println(schedHome);

    p = null;
    ProcessBuilder pb = new ProcessBuilder();
    if (OperatingSystem.getOperatingSystem().equals(OperatingSystem.unix)) {
        pb.directory(new File(schedHome + fs + "bin" + fs + "unix"));
        pb.command("/bin/bash", restart ? "scheduler-start" : "scheduler-start-clean",
                "-Dproactive.communication.protocol=pnp", "-Dproactive.pnp.port=9999");
        pb.environment().put("SchedulerTStarter", "SchedulerTStarter");
        p = pb.start();

    } else {

        pb.directory(new File(schedHome + fs + "bin" + fs + "windows"));

        pb.command("cmd.exe", "/c", restart ? "scheduler-start.bat" : "scheduler-start-clean.bat",
                "-Dproactive.communication.protocol=pnp", "-Dproactive.pnp.port=9999");
        pb.environment().put("SchedulerTStarter", "SchedulerTStarter");
        p = pb.start();

    }

    IOTools.LoggingThread lt1 = new IOTools.LoggingThread(p.getInputStream(), "[SchedulerTStarter]",
            System.out);
    Thread t1 = new Thread(lt1, "SchedulerTStarter");
    t1.setDaemon(true);
    t1.start();

    // waiting the initialization
    RMAuthentication rmAuth = RMConnection.waitAndJoin("pnp://localhost:9999");

    System.out.println("RM successfully joined.");

    SchedulerConnection.waitAndJoin("pnp://localhost:9999");
    System.out.println("Scheduler successfully joined.");

}

From source file:Main.java

public static ThreadFactory newGenericThreadFactory(final String processName, final boolean isDaemon) {
    return new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override/*from  www .  j  av  a  2s  .  c o m*/
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r,
                    String.format("%s_%d", processName, this.threadIndex.incrementAndGet()));
            thread.setDaemon(isDaemon);
            return thread;
        }
    };
}

From source file:de.flapdoodle.embed.process.io.file.FileCleaner.java

public synchronized static void forceDeleteOnExit(File fileOrDir) {
    //      FileUtils.forceDeleteOnExit(file);
    if (cleaner == null) {
        cleaner = new Cleaner();

        Thread cleanerThread = new Thread(new CleanerThreadRunner(cleaner));
        cleanerThread.setDaemon(true);
        cleanerThread.start();//from  w  w  w. j a  v  a2 s .c om

        Runtime.getRuntime().addShutdownHook(new Thread(new CleanerShutdownHook(cleaner)));
    }

    cleaner.forceDelete(fileOrDir);
}

From source file:Main.java

public static ThreadFactory newGenericThreadFactory(final String processName, final int threads,
        final boolean isDaemon) {
    return new ThreadFactory() {
        private AtomicInteger threadIndex = new AtomicInteger(0);

        @Override//from w  ww  . ja v a2 s . co m
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r,
                    String.format("%s_%d_%d", processName, threads, this.threadIndex.incrementAndGet()));
            thread.setDaemon(isDaemon);
            return thread;
        }
    };
}

From source file:com.google.zxing.client.android.result.supplement.SupplementalInfoRetriever.java

private static synchronized ExecutorService getExecutorService() {
    if (executorInstance == null) {
        executorInstance = Executors.newCachedThreadPool(new ThreadFactory() {
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setDaemon(true);
                return t;
            }//  w w  w . j  a v  a 2  s  .  com
        });
    }
    return executorInstance;
}

From source file:de.uni_koeln.spinfo.maalr.sigar.SigarWrapper.java

private static void initialize() {
    logger.info("Initializing...");
    String libBase = "/hyperic-sigar-1.6.5/sigar-bin/lib/";
    try {// ww w  . j a  v a  2s.c o  m
        String prefix = "libsigar";
        if (SystemUtils.IS_OS_WINDOWS) {
            prefix = "sigar";
        }
        String arch = getSystemArch();
        String suffix = getSystemSuffix();
        String resourceName = prefix + "-" + arch + "-" + suffix;

        logger.info("Native library: " + resourceName);

        String resource = libBase + resourceName;
        URL toLoad = SigarWrapper.class.getResource(resource);
        File home = new File(System.getProperty("user.home"));
        File libs = new File(home, ".maalr/libs/sigar");
        libs.mkdirs();
        File tmp = new File(libs, resourceName);
        tmp.deleteOnExit();
        FileOutputStream fos = new FileOutputStream(tmp);
        InputStream in = toLoad.openStream();
        int i;
        while ((i = in.read()) != -1) {
            fos.write(i);
        }
        in.close();
        fos.close();
        logger.info("Library copied to " + tmp.getAbsolutePath());
        String oldPath = System.getProperty("java.library.path");
        System.setProperty("java.library.path", oldPath + SystemUtils.PATH_SEPARATOR + libs.getAbsolutePath());
        logger.info("java.library.path updated: " + System.getProperty("java.library.path"));
        executors = Executors.newScheduledThreadPool(1, new ThreadFactory() {

            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setDaemon(true);
                return t;
            }
        });
        logger.info("Initialization completed.");
    } catch (Exception e) {
        logger.error("Failed to initialize!", e);
    }
}

From source file:net.geoprism.gis.geoserver.GeoserverInitializer.java

public static void setup() {
    GeoserverInitializer init = new GeoserverInitializer();

    try {/*from w  ww .j  a v  a 2  s .c  o  m*/
        initLog.debug("Attempting to initialize context.");

        // create another thread to avoid blocking the one starting the webapps.
        Thread t = new Thread(new CheckThread());
        t.setUncaughtExceptionHandler(init);
        t.setDaemon(true);
        t.start();

        initLog.debug("Context initialized...[" + GeoserverInitializer.class + "] started.");
    } catch (Throwable t) {
        initLog.error("Could not initialize context.", t);
    }

    // Start the mapping database view cleanup thread
    Thread t = new Thread(cleanup);
    t.setUncaughtExceptionHandler(init);
    t.setDaemon(true);
    t.start();

    // scheduler.scheduleWithFixedDelay(new CleanupRunnable(), 1, 5, TimeUnit.MINUTES);
}

From source file:Main.java

/**
 * Utility method that sets name, daemon status and starts passed thread.
 * @param t thread to frob/*from   www . j  a  v a 2 s . com*/
 * @param name new name
 * @param handler A handler to set on the thread.  Pass null if want to
 * use default handler.
 * @return Returns the passed Thread <code>t</code>.
 */
public static Thread setDaemonThreadRunning(final Thread t, final String name,
        final UncaughtExceptionHandler handler) {
    t.setName(name);
    if (handler != null) {
        t.setUncaughtExceptionHandler(handler);
    }
    t.setDaemon(true);
    t.start();
    return t;
}

From source file:smn.learn.jcassandra.TsubscribeServer.java

public static void serve(String[] args) throws Exception {
    if (args.length < 1) {
        System.err.println("Please specify document root directory");
        System.exit(1);/*from   w ww.  ja  v  a  2 s  . com*/
    }
    Thread t = new RequestListenerThread(8080, args[0]);
    t.setDaemon(false);
    t.start();
}