List of usage examples for java.lang Thread setDaemon
public final void setDaemon(boolean on)
From source file:com.googlecode.shutdownlistener.ContextShutdownTest.java
@Test(timeout = 1000) public void testDefaultShutdownAndWait() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/shutdownTestContext.xml"); final ApplicationContextShutdownWrapper shutdownWrapper = new ApplicationContextShutdownWrapper(context); Assert.assertFalse(StaticTrackingShutdownListener.isShutdown()); final Thread shutdownCall = new Thread(new Runnable() { public void run() { try { Thread.sleep(100); ShutdownUtility.main(new String[] {}); ShutdownUtility// ww w. j av a 2 s . c o m .main(new String[] { ShutdownConfiguration.getInstance().getShutdownWaitCommand() }); } catch (Exception e) { Assert.fail("failed to shutdown: " + e); } } }); shutdownCall.setDaemon(true); shutdownCall.start(); shutdownWrapper.waitForShutdown(); Assert.assertTrue(StaticTrackingShutdownListener.isShutdown()); shutdownWrapper.waitForShutdown(); }
From source file:com.vinay.simpleadserver.cache.AdServerInMemoryCache.java
/** * * @param adServerTimerInterval Time in seconds in which the InMemory Cache * cleans up expired objects//w w w.j a va 2 s . co m * @param maxItems The maximum number of key/value pairs the InMemory cache * can support. */ public AdServerInMemoryCache(final long adServerTimerInterval, int maxItems) { adServerCacheMap = new LRUMap(maxItems); if (adServerTimerInterval > 0) { Thread t; t = new Thread(new Runnable() { @Override public void run() { while (true) { try { Thread.sleep(adServerTimerInterval * 1000); } catch (InterruptedException ex) { } cleanup(); } } }); t.setDaemon(true); t.start(); } }
From source file:net.sourceforge.subsonic.service.PodcastService.java
public PodcastService() { ThreadFactory threadFactory = new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); return t; }/*w w w. ja v a 2 s . c om*/ }; refreshExecutor = Executors.newFixedThreadPool(5, threadFactory); downloadExecutor = Executors.newFixedThreadPool(3, threadFactory); scheduledExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory); }
From source file:com.googlecode.shutdownlistener.ContextShutdownTest.java
@Test(timeout = 1000) public void testDefaultShutdownNoWait() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/shutdownTestContext.xml"); final ApplicationContextShutdownWrapper shutdownWrapper = new ApplicationContextShutdownWrapper(context); Assert.assertFalse(StaticTrackingShutdownListener.isShutdown()); final Thread shutdownCall = new Thread(new Runnable() { public void run() { try { Thread.sleep(100); ShutdownUtility.main(new String[] {}); ShutdownUtility//from w w w . j a v a2 s. co m .main(new String[] { ShutdownConfiguration.getInstance().getShutdownNoWaitCommand() }); } catch (Exception e) { Assert.fail("failed to shutdown: " + e); } } }); shutdownCall.setDaemon(true); shutdownCall.start(); shutdownWrapper.waitForShutdown(); Assert.assertTrue(StaticTrackingShutdownListener.isShutdown()); shutdownWrapper.waitForShutdown(); }
From source file:com.googlecode.shutdownlistener.ContextShutdownTest.java
@Test(timeout = 1000) public void testCustomShutdownNoWait() throws Exception { System.setProperty(ShutdownConfiguration.CONFIGURATION_SYSTEM_PROPERTY, "/shutdown-listener-test.properties"); final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/shutdownTestContext.xml"); final ApplicationContextShutdownWrapper shutdownWrapper = new ApplicationContextShutdownWrapper(context); Assert.assertFalse(StaticTrackingShutdownListener.isShutdown()); final Thread shutdownCall = new Thread(new Runnable() { public void run() { try { Thread.sleep(100); ShutdownUtility.main(new String[] {}); ShutdownUtility/* w ww . j av a 2s. c o m*/ .main(new String[] { ShutdownConfiguration.getInstance().getShutdownNoWaitCommand() }); } catch (Exception e) { Assert.fail("failed to shutdown: " + e); } } }); shutdownCall.setDaemon(true); shutdownCall.start(); shutdownWrapper.waitForShutdown(); Assert.assertTrue(StaticTrackingShutdownListener.isShutdown()); shutdownWrapper.waitForShutdown(); }
From source file:com.hangum.tadpole.commons.admin.core.editors.sqlaudit.AdminSQLAuditEditor.java
private void callbackui() { pushSession.start();/*from w w w. ja v a 2 s .c om*/ Thread thread = new Thread(startUIThread()); thread.setDaemon(true); thread.start(); }
From source file:com.hangum.tadpole.mongodb.core.editors.dbInfos.comosites.InstanceInformationComposite.java
/** * start instance monitoring/*from ww w . ja va 2 s .co m*/ */ private void startInstanceMon() { if (!isUIThreadRunning) { spsInstance.start(); Thread bgThread = new Thread(startUIThread()); bgThread.setDaemon(true); bgThread.start(); btnStart.setEnabled(false); btnStop.setEnabled(true); } }
From source file:immf.AppNotifications.java
public AppNotifications(Config conf, StatusManager status) { this.status = status; this.email = conf.getForwardPushEmail(); this.password = conf.getForwardPushPassword(); this.message = conf.getForwardPushMessage(); if (this.message == null) this.message = Message; this.sound = soundFile(conf.getForwardPushSound()); this.iconUrl = conf.getForwardPushIconUrl(); if (this.iconUrl.isEmpty()) this.iconUrl = IconUrl; this.pushFromInfo = conf.isForwardPushFrom(); this.pushSubjectInfo = conf.isForwardPushSubject(); this.pushReplyButton = conf.isForwardPushReplyButton(); this.dnsCache = conf.isForwardPushUseDnsCache(); this.credentials = status.getPushCredentials(); if (this.credentials == null) this.credentials = ""; if (this.email.length() > 0 && this.password.length() > 0) { Thread t = new Thread(this); t.setName("AppNotifications"); t.setDaemon(true); t.start();//from ww w . ja va 2 s. co m } else { if (this.credentials.length() > 0) this.setCredentials(""); } }
From source file:com.redhat.red.offliner.Main.java
/** * Sets up components needed for the download process, including the {@link ExecutorCompletionService}, * {@link java.util.concurrent.Executor}, {@link org.apache.http.client.HttpClient}, and {@link ArtifactListReader} * instances. If baseUrls were provided on the command line, it will initialize the "global" baseUrls list to that. * Otherwise it will use {@link Options#DEFAULT_REPO_URL} and {@link Options#CENTRAL_REPO_URL} as the default * baseUrls. If specified, configures the HTTP proxy and username/password for authentication. * @throws MalformedURLException In case an invalid {@link URL} is given as a baseUrl. *//*from ww w .j a va2 s.c om*/ protected void init() throws MalformedURLException { int threads = opts.getThreads(); executorService = Executors.newFixedThreadPool(threads, (final Runnable r) -> { // executorService = Executors.newCachedThreadPool( ( final Runnable r ) -> { final Thread t = new Thread(r); t.setDaemon(true); return t; }); executor = new ExecutorCompletionService<>(executorService); errors = new ConcurrentHashMap<String, Throwable>(); final PoolingHttpClientConnectionManager ccm = new PoolingHttpClientConnectionManager(); ccm.setMaxTotal(opts.getConnections()); final HttpClientBuilder builder = HttpClients.custom().setConnectionManager(ccm); final String proxy = opts.getProxy(); String proxyHost = proxy; int proxyPort = 8080; if (proxy != null) { final int portSep = proxy.lastIndexOf(':'); if (portSep > -1) { proxyHost = proxy.substring(0, portSep); proxyPort = Integer.parseInt(proxy.substring(portSep + 1)); } final HttpRoutePlanner planner = new DefaultProxyRoutePlanner(new HttpHost(proxyHost, proxyPort)); builder.setRoutePlanner(planner); } client = builder.build(); final CredentialsProvider creds = new BasicCredentialsProvider(); cookieStore = new BasicCookieStore(); baseUrls = opts.getBaseUrls(); if (baseUrls == null) { baseUrls = new ArrayList<>(); } List<String> repoUrls = (baseUrls.isEmpty() ? DEFAULT_URLS : baseUrls); System.out.println("Planning download from:\n " + StringUtils.join(repoUrls, "\n ")); for (String repoUrl : repoUrls) { if (repoUrl != null) { final String user = opts.getUser(); if (user != null) { final URL u = new URL(repoUrl); final AuthScope as = new AuthScope(u.getHost(), UrlUtils.getPort(u)); creds.setCredentials(as, new UsernamePasswordCredentials(user, opts.getPassword())); } } if (proxy != null) { final String proxyUser = opts.getProxyUser(); if (proxyUser != null) { creds.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, opts.getProxyPassword())); } } } artifactListReaders = new ArrayList<>(3); artifactListReaders.add(new FoloReportArtifactListReader()); artifactListReaders.add(new PlaintextArtifactListReader()); artifactListReaders.add(new PomArtifactListReader(opts.getSettingsXml(), opts.getTypeMapping(), creds)); }