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.clustercontrol.agent.winevent.WinEventResultForwarder.java

private WinEventResultForwarder() {
    {/*w  ww . j  av  a 2 s .co m*/
        String key = "monitor.winevent.forwarding.queue.maxsize";
        int valueDefault = 5000;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _queueMaxSize = value;
    }

    {
        String key = "monitor.winevent.forwarding.transport.maxsize";
        int valueDefault = 100;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportMaxSize = value;
    }

    {
        String key = "monitor.winevent.forwarding.transport.maxtries";
        int valueDefault = 900;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportMaxTries = value;
    }

    {
        String key = "monitor.winevent.forwarding.transport.interval.size";
        int valueDefault = 15;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportIntervalSize = value;
    }

    {
        String key = "monitor.winevent.forwarding.transport.interval.msec";
        long valueDefault = 1000L;
        String str = AgentProperties.getProperty(key);
        long value = valueDefault;
        try {
            value = Long.parseLong(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportIntervalMSec = value;
    }

    _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        private volatile int _count = 0;

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, WinEventResultForwarder.class.getSimpleName() + _count++);
            t.setDaemon(true);
            return t;
        }
    });

    if (_transportIntervalMSec != -1) {
        _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec,
                TimeUnit.MILLISECONDS);
    }
}

From source file:com.clustercontrol.agent.log.LogfileResultForwarder.java

private LogfileResultForwarder() {
    {/*from w  w w  .j a v a2  s  .  co m*/
        String key = "monitor.logfile.forwarding.queue.maxsize";
        int valueDefault = 5000;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _queueMaxSize = value;
    }

    {
        String key = "monitor.logfile.forwarding.transport.maxsize";
        int valueDefault = 100;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportMaxSize = value;
    }

    {
        String key = "monitor.logfile.forwarding.transport.maxtries";
        int valueDefault = 900;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportMaxTries = value;
    }

    {
        String key = "monitor.logfile.forwarding.transport.interval.size";
        int valueDefault = 15;
        String str = AgentProperties.getProperty(key);
        int value = valueDefault;
        try {
            value = Integer.parseInt(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportIntervalSize = value;
    }

    {
        String key = "monitor.logfile.forwarding.transport.interval.msec";
        long valueDefault = 1000L;
        String str = AgentProperties.getProperty(key);
        long value = valueDefault;
        try {
            value = Long.parseLong(str);
            if (value != -1 && value < 1) {
                throw new NumberFormatException();
            }
        } catch (NumberFormatException e) {
            value = valueDefault;
        } finally {
            log.info(key + " uses value \"" + value + "\". (configuration = \"" + str + "\")");
        }
        _transportIntervalMSec = value;
    }

    _scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        private volatile int _count = 0;

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, LogfileResultForwarder.class.getSimpleName() + _count++);
            t.setDaemon(true);
            return t;
        }
    });

    if (_transportIntervalMSec != -1) {
        _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec,
                TimeUnit.MILLISECONDS);
    }
}

From source file:com.espertech.esper.dataflow.core.EPDataFlowInstanceImpl.java

public synchronized void start() {
    checkExecCompleteState();//w w  w  . jav  a2  s . com
    checkExecCancelledState();
    checkExecRunningState();

    callOperatorOpen();

    final AtomicInteger countdown = new AtomicInteger(sourceRunnables.size());
    threads = new ArrayList<Thread>();
    for (int i = 0; i < sourceRunnables.size(); i++) {
        GraphSourceRunnable runnable = sourceRunnables.get(i);
        String threadName = "esper." + dataFlowName + "-" + i;
        Thread thread = new Thread(runnable, threadName);
        thread.setContextClassLoader(Thread.currentThread().getContextClassLoader());
        thread.setDaemon(true);
        runnable.addCompletionListener(new CompletionListener() {
            public void completed() {
                int remaining = countdown.decrementAndGet();
                if (remaining == 0) {
                    EPDataFlowInstanceImpl.this.completed();
                }
            }
        });
        threads.add(thread);
        thread.start();
    }
    setState(EPDataFlowState.RUNNING);
}

From source file:com.ericsson.research.trap.spi.transports.ApacheClientHttpTransport.java

@Override
protected void internalConnect() throws TrapException {

    this.updateConfig();

    // Make a request to get a new TransportID
    if (!this.isClientConfigured()) {
        this.logger.debug(
                "HTTP Transport not properly configured... Unless autoconfigure is enabled (and another transport succeeds) this transport will not be available.");
        this.setState(TrapTransportState.ERROR);
        return;//from  ww  w .ja  v  a2s .c  om
    }

    try {
        this.running = true;
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = this.openGet(this.connectUrl);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream is = null;
            InputStreamReader isr = null;
            try {
                is = entity.getContent();
                isr = new InputStreamReader(is, Charset.forName("UTF-8"));

                StringWriter sr = new StringWriter();
                int ch = 0;

                while ((ch = isr.read()) != -1)
                    sr.write(ch);

                String rawUrl = sr.toString();

                String urlBase = this.connectUrl.toString();

                if (urlBase.endsWith("/"))
                    urlBase += rawUrl;
                else
                    urlBase += "/" + rawUrl;

                this.activeUrl = URI.create(urlBase);

                // Start a new thread for polling
                Thread t = new Thread(this);
                t.setDaemon(true);
                t.start();

                this.postclient = new DefaultHttpClient();

                // Change state to connected
                this.setState(TrapTransportState.CONNECTED);
            } finally {
                if (is != null)
                    is.close();

                if (isr != null)
                    isr.close();
            }
        }

    } catch (Exception e) {
        this.setState(TrapTransportState.ERROR);
        throw new TrapException(e);
    }

}

From source file:com.igormaznitsa.sciareto.preferences.PreferencesManager.java

private PreferencesManager() {
    this.prefs = Preferences.userNodeForPackage(PreferencesManager.class);
    String packedUuid = this.prefs.get(PROPERTY_UUID, null);
    if (packedUuid == null) {
        try {/*w  w  w .  j ava  2 s . c  o  m*/
            final UUID newUUID = UUID.randomUUID();
            packedUuid = Base64.encodeBase64String(IOUtils.packData(newUUID.toString().getBytes("UTF-8")));
            this.prefs.put(PROPERTY_UUID, packedUuid);
            this.prefs.flush();
            LOGGER.info("Generated new installation UUID : " + newUUID.toString());

            final Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    LOGGER.info("Send first start metrics");
                    com.igormaznitsa.sciareto.metrics.MetricsService.getInstance().onFirstStart();
                }
            }, "SCIARETO_FIRST_START_METRICS");
            thread.setDaemon(true);
            thread.start();

        } catch (Exception ex) {
            LOGGER.error("Can't generate UUID", ex);
        }
    }
    try {
        this.installationUUID = UUID
                .fromString(new String(IOUtils.unpackData(Base64.decodeBase64(packedUuid)), "UTF-8"));
        LOGGER.info("Installation UUID : " + this.installationUUID.toString());
    } catch (UnsupportedEncodingException ex) {
        LOGGER.error("Can't decode UUID", ex);
        throw new Error("Unexpected error", ex);
    }
}

From source file:com.igormaznitsa.sciareto.metrics.MetricsService.java

public void onFirstStart() {
    LOGGER.info("Starting statistics send");
    final Thread thread = new Thread(new Runnable() {
        @Override//  w  ww  .  jav a  2s. c  o  m
        public void run() {
            try {
                doFirstStartAction();
            } catch (Exception ex) {
                LOGGER.error("Can't send statistics", ex);
            }
        }
    }, "SCIARETO_STATISTIC_SEND");
    thread.setDaemon(true);
    thread.start();
}

From source file:fi.aluesarjat.prototype.DataService.java

@SuppressWarnings("unchecked")
public void loadData(DataServiceMode mode) throws IOException {
    logger.info("adding namespaces");

    String dimensionNs = baseURI + ScovoDatasetHandler.DIMENSION_NS;

    Map<String, String> namespaces = new HashMap<String, String>(Namespaces.DEFAULT);
    namespaces.put(GEO.NS, "geo");
    namespaces.put(SCV.NS, "scv");
    namespaces.put(META.NS, "meta");
    namespaces.put(DC.NS, "dc");
    namespaces.put(DCTERMS.NS, "dcterms");
    namespaces.put(STAT.NS, "stat");
    namespaces.put(SKOS.NS, "skos");
    namespaces.put(dimensionNs, "dimension");
    namespaces.put(baseURI + ScovoDatasetHandler.DATASET_CONTEXT_BASE, "dataset");
    namespaceHandler.addNamespaces(namespaces);

    logger.info("initializing data");

    if (datasets == null) {
        //            datasets = IOUtils.readLines(getStream("/data/datasets"));
        if (datasetsList.startsWith("classpath:")) {
            datasets = IOUtils.readLines(getStream(datasetsList.substring("classpath:".length())));
        } else {/*  w  w w.j  av  a  2s . c  om*/
            InputStream in = new URL(datasetsList).openStream();
            datasets = IOUtils.readLines(in);
            in.close();
        }
    }

    if (mode == DataServiceMode.PARALLEL) {
        for (String d : datasets) {
            final String datasetDef = d.trim();
            Thread thread = new Thread() {
                @Override
                public void run() {
                    importData(datasetDef, forceReload);
                }
            };
            thread.setDaemon(true);
            thread.start();
        }

    } else if (mode == DataServiceMode.THREADED) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                for (String d : datasets) {
                    importData(d.trim(), forceReload);
                }
            }
        };
        thread.setDaemon(true);
        thread.start();

    } else {
        for (String d : datasets) {
            importData(d.trim(), forceReload);
        }
    }
}

From source file:org.apache.awf.web.SystemTest.java

@BeforeClass
public static void setup() {

    final Configuration configuration = new Configuration();
    configuration.setCreateETags(true).setStaticDirectory("src/test/resources");
    configuration.addHandler("/", new ExampleRequestHandler());
    configuration.addHandler("/w", new WRequestHandler());
    configuration.addHandler("/ww", new WWRequestHandler());
    configuration.addHandler("/wwfw", new WWFWRequestHandler());
    configuration.addHandler("/wfwf", new WFWFRequestHandler());
    configuration.addHandler("/wfffwfff", new WFFFWFFFRequestHandler());
    configuration.addHandler("/delete", new DeleteRequestHandler());
    configuration.addHandler("/post", new PostRequestHandler());
    configuration.addHandler("/put", new PutRequestHandler());
    configuration.addHandler("/capturing/([0-9]+)", new CapturingRequestRequestHandler());
    configuration.addHandler("/throw", new ThrowingHttpExceptionRequestHandler());
    configuration.addHandler("/async_throw", new AsyncThrowingHttpExceptionRequestHandler());
    configuration.addHandler("/no_body", new NoBodyRequestHandler());
    configuration.addHandler("/moved_perm", new MovedPermanentlyRequestHandler());
    configuration.addHandler("/static_file_handler", new UserDefinedStaticContentHandler());
    configuration.addHandler("/450kb_body", new _450KBResponseEntityRequestHandler());
    configuration.addHandler("/echo", new EchoingPostBodyRequestHandler());
    configuration.addHandler("/authenticated", new AuthenticatedRequestHandler());
    configuration.addHandler("/query_params", new QueryParamsRequestHandler());
    configuration.addHandler("/chunked", new ChunkedRequestHandler());

    /*/*from   w w w.j a  v a 2  s . co m*/
     * Start server instance from a new thread because the start invocation
     * is blocking (invoking thread will be I/O loop thread).
     */
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {

            HttpServer server = new HttpServer(configuration);
            server.listen(PORT);
            IOLoop.INSTANCE.start();
        }
    });
    thread.setDaemon(true);
    thread.start();
}

From source file:org.marietjedroid.connect.MarietjeMessenger.java

/**
 * Starts running the threads//  w  ww  . j a  va2  s.  co  m
 * 
 * @throws MarietjeException
 */
public void run() throws MarietjeException {
    if (this.running)
        throw new IllegalStateException("Already running");
    this.running = true;
    if (this.token != null) {
        this.doRequest(null);
    }
    Thread t1 = new Thread(new MessageDispatcher());
    t1.setDaemon(true);
    t1.start();

    Thread t2 = new Thread(new Requester());
    t2.setDaemon(true);
    t2.start();
}

From source file:de.csw.linkgenerator.plugin.lucene.IndexRebuilder.java

public synchronized int startRebuildIndex(XWikiContext context) {
    if (rebuildInProgress) {
        LOG.warn("Cannot launch rebuild because a build is in progress");
        return LucenePluginApi.REBUILD_IN_PROGRESS;
    } else {//from  w w w.j  a  v  a  2  s  .  com
        this.rebuildInProgress = true;
        this.context = context;
        Thread indexRebuilderThread = new Thread(this, "Lucene Index Rebuilder");
        // The JVM should be allowed to shutdown while this thread is running
        indexRebuilderThread.setDaemon(true);
        // Client requests are more important than indexing
        indexRebuilderThread.setPriority(3);
        // Finally, start the rebuild in the background
        indexRebuilderThread.start();
        // Too bad that now we can't tell how many items are there to be indexed...
        return 0;
    }
}