List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:ai.grakn.engine.session.GraqlSession.java
GraqlSession(Session session, GraknSession factory, String outputFormat, boolean showImplicitTypes, boolean infer, boolean materialise) { this.showImplicitTypes = showImplicitTypes; this.infer = infer; this.materialise = materialise; this.session = session; this.factory = factory; this.outputFormat = outputFormat; this.printer = getPrinter(); queryExecutor.execute(() -> {// w w w . jav a2s.c o m try { refreshGraph(); sendTypes(); sendEnd(); } catch (Throwable e) { LOG.error(getFullStackTrace(e)); sendError(e.getMessage()); sendEnd(); session.close(); throw e; } }); // Begin sending pings Thread thread = new Thread(this::ping, "graql-session-ping"); thread.setDaemon(true); thread.start(); }
From source file:com.github.restdriver.clientdriver.integration.VerifyWithinTest.java
@Test public void verifyingSingleRequestWithinATimePeriodWorks() throws Exception { clientDriver.addExpectation(onRequestTo("/foo"), giveEmptyResponse().within(2000, TimeUnit.MILLISECONDS)); Thread thread = new Thread(new Runnable() { @Override//from w w w . ja va 2 s. com public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo"); } }); thread.setDaemon(true); thread.start(); clientDriver.verify(); }
From source file:com.github.restdriver.clientdriver.integration.VerifyWithinTest.java
@Test public void singleRequestThatIsNotMatchedInTimeFailsToVerify() throws Exception { thrown.expect(ClientDriverFailedExpectationException.class); clientDriver.addExpectation(onRequestTo("/foo"), giveEmptyResponse().within(200, TimeUnit.MILLISECONDS)); Thread thread = new Thread(new Runnable() { @Override/* w w w . ja v a2 s . c om*/ public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo"); } }); thread.setDaemon(true); thread.start(); clientDriver.verify(); }
From source file:com.clustercontrol.agent.custom.CommandResultForwarder.java
private CommandResultForwarder() { {/* ww w .j ava 2 s.c om*/ String key = "monitor.custom.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.custom.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.custom.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.custom.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.custom.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, CommandResultForwarder.class.getSimpleName() + _count++); t.setDaemon(true); return t; } }); if (_transportIntervalMSec != -1) { _scheduler.scheduleWithFixedDelay(new ScheduledTask(), 0, _transportIntervalMSec, TimeUnit.MILLISECONDS); } }
From source file:disko.flow.analyzers.FullRelexAnalyzer.java
/** * Initialize the pool of LinkParserClients, creating CLIENT_POOL_SIZE * instances, which connects to ports FIRST_PORT, FIRST_PORT+1, ..., * FIRST_PORT+(CLIENT_POOL_SIZE-1)//from w w w . ja v a 2 s .com */ private void initializePool() throws InterruptedException { sentenceAlgorithmApplier = new SentenceAlgorithmApplier(); // phraseMarkup = new PhraseMarkup(); if (morphy == null) morphy = MorphyFactory.getImplementation(); if ((hosts == null) || (hosts.size() == 0)) { for (int i = 0; i < DEFAULT_CLIENT_COUNT; i++) { addHost(DEFAULT_HOST, DEFAULT_FIRST_PORT + i); } } final ClassLoader loader = Thread.currentThread().getContextClassLoader(); // +1 submission thread exec = Executors.newFixedThreadPool(hosts.size() + 1, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setContextClassLoader(loader); t.setDaemon(true); return t; } }); pool = new ArrayBlockingQueue<RelexContext>(hosts.size() + inProcessParsers); for (HostPort hp : hosts) { RemoteLGParser parser = new RemoteLGParser(); parser.getLinkGrammarClient().setHostname(hp.host); parser.getLinkGrammarClient().setPort(hp.port); configureParser(parser); RelexContext context = new RelexContext(parser, morphy); pool.put(context); } for (int i = hosts.size(); i < pool.size(); i++) { LocalLGParser parser = new LocalLGParser(); configureParser(parser); RelexContext context = new RelexContext(parser, morphy); pool.put(context); } }
From source file:io.snappydata.impl.SnappyHiveCatalog.java
public SnappyHiveCatalog() { final ThreadGroup hmsThreadGroup = LogWriterImpl.createThreadGroup(THREAD_GROUP_NAME, Misc.getI18NLogWriter());/*from w ww . j ava2 s.com*/ ThreadFactory hmsClientThreadFactory = new ThreadFactory() { private int next = 0; @SuppressWarnings("NullableProblems") public Thread newThread(Runnable command) { Thread t = new Thread(hmsThreadGroup, command, "HiveMetaStore Client-" + next++); t.setDaemon(true); return t; } }; hmsQueriesExecutorService = Executors.newFixedThreadPool(1, hmsClientThreadFactory); // just run a task to initialize the HMC for the thread. // Assumption is that this should be outside any lock HMSQuery q = getHMSQuery(); q.resetValues(HMSQuery.INIT, null, null, true); Future<Object> ret = hmsQueriesExecutorService.submit(q); try { ret.get(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.github.restdriver.clientdriver.integration.VerifyWithinTest.java
@Test public void multipleRequestsWhichAreMatchedInTimeWork() throws Exception { clientDriver.addExpectation(onRequestTo("/foo1"), giveEmptyResponse().within(5, TimeUnit.SECONDS)); clientDriver.addExpectation(onRequestTo("/foo2"), giveEmptyResponse().within(5, TimeUnit.SECONDS)); Thread thread1 = new Thread(new Runnable() { @Override/*w ww . java 2s. c om*/ public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo1"); } }); thread1.setDaemon(true); Thread thread2 = new Thread(new Runnable() { @Override public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo2"); } }); thread2.setDaemon(true); thread1.start(); thread2.start(); clientDriver.verify(); }
From source file:com.github.restdriver.clientdriver.integration.VerifyWithinTest.java
@Test public void multipleRequestsOneOfWhichWasNotMatchedInTimeFailsToVerify() throws Exception { thrown.expect(ClientDriverFailedExpectationException.class); clientDriver.addExpectation(onRequestTo("/foo1"), giveEmptyResponse().within(200, TimeUnit.MILLISECONDS)); clientDriver.addExpectation(onRequestTo("/foo2"), giveEmptyResponse().within(1, TimeUnit.SECONDS)); Thread thread1 = new Thread(new Runnable() { @Override/* ww w . ja v a 2 s.co m*/ public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo1"); } }); thread1.setDaemon(true); Thread thread2 = new Thread(new Runnable() { @Override public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo2"); } }); thread2.setDaemon(true); thread1.start(); thread2.start(); clientDriver.verify(); }
From source file:net.sbbi.upnp.DiscoveryAdvertisement.java
private void startDevicesListenerThread() throws IOException { synchronized (singleton) { if (!inService) { this.startMultiCastSocket(); Thread deamon = new Thread(this, "DiscoveryAdvertisement daemon"); deamon.setDaemon(daemon); deamon.start();/* www .j a va 2 s . c o m*/ // wait for the thread to be started while (!inService) { // let's wait a few ms try { Thread.sleep(2); } catch (InterruptedException ex) { // don t care } } } } }
From source file:imitationLearning.WordSequenceCache.java
/** * * @param timeToLive/*from w w w . j a v a2 s .co m*/ * @param timerInterval * @param maxItems */ public WordSequenceCache(long timeToLive, final long timerInterval, int maxItems) { this.timeToLive = timeToLive * 1_000; cacheMap = new LRUMap(maxItems); if (timeToLive > 0 && timerInterval > 0) { Thread t = new Thread(() -> { while (true) { try { Thread.sleep(timerInterval * 1_000); } catch (InterruptedException ex) { } cleanup(); } }); t.setDaemon(true); t.start(); } }