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:eu.flatworld.worldexplorer.layer.bmng.BMNGHTTPProvider.java

public BMNGHTTPProvider() {
    LogX.log(Level.INFO, NAME + " starting");
    client = new HttpClient();
    Thread queueRunner = new Thread(this, this.getClass().getName() + "_queueRunner");
    queueRunner.setDaemon(true);
    queueRunner.start();/*  ww  w.  j a  v a 2  s. co m*/
}

From source file:com.garyclayburg.data.ServiceAttributeConfig.java

@Bean
@Profile({ "mongoembedded", "mongolocal" }) //i.e. don't start up thread when running tests
public WatchDir watchDir() throws IOException {
    ScriptRunner scriptRunner = scriptRunner();
    String[] roots = scriptRunner.getRoots();
    if (roots == null) {
        log.error("Groovy root not configured");
        return null;
    }//from ww  w.ja  v a2  s .c o m
    Path watchPath = Paths.get(roots[0]);
    WatchDir watcher = new WatchDir(watchPath, true);
    Thread t = new Thread(watcher, "groovyWatcher");
    t.setDaemon(true);
    t.start();

    return watcher;
}

From source file:org.kiji.checkin.CommandLogger.java

/**
 * Logs the command by POSTing the command to the Kiji checkin server.
 *
 * @param command is the command to log.
 * @param logAsynch determines whether or not to log the command asynchronously.
 *///from  www  .  j a v  a2 s  .c  o m
public void logCommand(KijiCommand command, boolean logAsynch) {
    if (mCheckinServerUri != null && !CheckinUtils.isCheckinDisabled()) {
        if (logAsynch) {
            Thread commandLogger = new CommandLoggerThread(command);
            commandLogger.setDaemon(true);
            commandLogger.start();
        } else {
            doLog(command);
        }
    }
}

From source file:ch.algotrader.concurrent.BasicThreadFactory.java

@Override
public Thread newThread(final Runnable r) {
    Thread thread = new Thread(this.threadGroup, r, this.name + "-" + this.count.incrementAndGet());
    if (this.daemon != null) {
        thread.setDaemon(this.daemon);
    }/*w  w w  .j  a v  a 2 s . c o  m*/
    return thread;
}

From source file:org.berlin.crawl.bom.BotLinkConsumerProducer.java

public void run() {
    try {//from   w  w w .j a va  2s.  co m
        final QueueMonitorThread monitor = new QueueMonitorThread();
        final Thread mn = new Thread(monitor);
        mn.setDaemon(false);
        mn.start();
        // Run until incomplete with processing //
        while (!completeWithProcessing) {
            // Loop until no other links are available //
            // We may need poison the queue so we can release
            consumeLink(queue.get().take());

            // Also add random delay between requests to avoid too much of an automated request
            final Random rr = new Random(System.currentTimeMillis());
            final int rdelay = rr.nextInt(LinkProcessQueueDatabase.LINK_PROCESS_DELAY + 400);
            Thread.sleep(LinkProcessQueueDatabase.LINK_PROCESS_DELAY + rdelay);
        } // End of the while //

        // We have to remove the thread //
    } catch (final Throwable ex) {
        ex.printStackTrace();
    } // End of the try - catch //
}

From source file:com.hellblazer.jackal.configuration.PartitionControllerConfig.java

protected ExecutorService controllerDispatchers() {
    final int id = partitionIdentity.id;
    return Executors.newCachedThreadPool(new ThreadFactory() {
        int count = 0;

        @Override//from   ww  w.j a v a  2  s  .com
        public Thread newThread(Runnable target) {
            Thread t = new Thread(target, String.format("Partition Controller Dispatcher[%s]", count++, id));
            t.setDaemon(true);
            t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error(String.format("Exception on %s", t), e);
                }
            });
            return t;
        }
    });
}

From source file:immf.ForwardMailPicker.java

public ForwardMailPicker(Config conf, ServerMain server) {
    this.conf = conf;
    this.server = server;
    int id = conf.getConfigId();

    if (true) {/*from   w ww. j  av  a 2  s .c o  m*/
        Thread t = new Thread(this);
        t.setName("ForwardMailPicker[" + id + "]");
        t.setDaemon(true);
        t.start();
    }
}

From source file:fr.inria.eventcloud.deployment.cli.launchers.EventCloudsManagementServiceDeployer.java

/**
 * Deploys an EventCloudsRegistry and an EventClouds Management Service in a
 * separate JVM according to the specified parameters.
 * /*  www .  j  a  va 2  s .co m*/
 * @param onRelease
 *            {@code true} if the lastest release of the EventCloud has to
 *            be used, {@code false} to use the latest snapshot version.
 * @param port
 *            the port used to deploy the EventClouds Management Service and
 *            which will also be used to deploy WS-Notification services.
 * @param urlSuffix
 *            the suffix appended to the end of the URL associated to the
 *            EventClouds Management Service to be deployed.
 * @param activateLoggers
 *            {@code true} if the loggers have to be activated,
 *            {@code false} otherwise.
 * @param properties
 *            additional Java properties set to the new JVM.
 * 
 * @return the endpoint URL of the EventClouds Management Service.
 * 
 * @throws IOException
 *             if an error occurs during the deployment.
 */
public synchronized static String deploy(boolean onRelease, int port, String urlSuffix, boolean activateLoggers,
        String... properties) throws IOException {
    if (eventCloudsManagementServiceProcess == null) {
        String binariesBaseUrl = EVENTCLOUD_BINARIES_URL;

        if (onRelease) {
            binariesBaseUrl += "releases/latest/";
        } else {
            binariesBaseUrl += "snapshots/latest/";
        }

        List<String> cmd = new ArrayList<String>();

        String javaBinaryPath = System.getProperty("java.home") + File.separator + "bin" + File.separator
                + "java";
        if (System.getProperty("os.name").startsWith("Windows")) {
            javaBinaryPath = javaBinaryPath + ".exe";
        }
        cmd.add(javaBinaryPath);

        cmd.add("-cp");
        cmd.add(addClassPath(binariesBaseUrl + "libs/"));

        cmd.addAll(addProperties(binariesBaseUrl + "resources/", activateLoggers));

        Collections.addAll(cmd, properties);

        cmd.add(EventCloudsManagementServiceDeployer.class.getCanonicalName());
        cmd.add(Integer.toString(port));
        cmd.add(urlSuffix);

        final ProcessBuilder processBuilder = new ProcessBuilder(cmd.toArray(new String[cmd.size()]));
        processBuilder.redirectErrorStream(true);
        eventCloudsManagementServiceProcess = processBuilder.start();

        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(eventCloudsManagementServiceProcess.getInputStream()));
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                String line = null;
                try {
                    while ((line = reader.readLine()) != null) {
                        if (!servicesDeployed.getValue() && line.contains(LOG_MANAGEMENT_WS_DEPLOYED)) {
                            servicesDeployed.setValue(true);
                            synchronized (servicesDeployed) {
                                servicesDeployed.notifyAll();
                            }
                        }
                        System.out.println("ECManagement " + line);
                    }
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        });
        t.setDaemon(true);
        t.start();

        synchronized (servicesDeployed) {
            while (!servicesDeployed.getValue()) {
                try {
                    servicesDeployed.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        StringBuilder eventCloudsManagementWsEndpoint = new StringBuilder("http://");
        eventCloudsManagementWsEndpoint.append(ProActiveInet.getInstance().getInetAddress().getHostAddress());
        eventCloudsManagementWsEndpoint.append(':');
        eventCloudsManagementWsEndpoint.append(port);
        eventCloudsManagementWsEndpoint.append('/');
        eventCloudsManagementWsEndpoint.append(urlSuffix);
        return eventCloudsManagementWsEndpoint.toString();
    } else {
        throw new IllegalStateException("EventClouds management process already deployed");
    }
}

From source file:neembuu.httpserver.VFStoHttpServer.java

private void create(int port) throws IOException {

    HttpProcessor httpproc = new BasicHttpProcessor();

    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    registry.register("*", new VFSHandler(fs));
    HttpService httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory());
    httpService.setHandlerResolver(registry);
    SSLServerSocketFactory sf = null;

    Thread t = new RequestListenerThread(port, httpService, sf);
    t.setDaemon(false);
    t.start();/*from  w  w  w.  j a  v a  2  s .co m*/
}

From source file:ai.grakn.engine.backgroundtasks.distributed.ClusterManager.java

/**
 * When you take over leadership start a new Scheduler instance and wait for it to complete.
 * @throws Exception/*  w  w w . j a  va2 s  .  co  m*/
 */
public void takeLeadership(CuratorFramework client) throws Exception {
    registerFailover(client);

    // Call close() in case of exceptions during open()
    scheduler = new Scheduler();
    scheduler.open();

    LOG.info(engineID + " has taken over the scheduler.");
    Thread schedulerThread = new Thread(scheduler);
    schedulerThread.setDaemon(true);
    schedulerThread.start();
    leaderInitLatch.countDown();
    schedulerThread.join();
}