List of usage examples for java.lang Thread isAlive
public final native boolean isAlive();
From source file:it.jnrpe.server.ThreadTimeoutWatcher.java
/** * Gets the oldest thread from the list and, if needed, kills it. * Threads no longer running gets removed from the list. * @return <code>true</code> if at leas one thread has been removed from the list. *//*from w w w. ja v a 2 s. c o m*/ private boolean killOldestThread() { // The thread in the first position is always the oldest one CThreadData td = (CThreadData) m_ThreadList.get(0); Thread t = td.getThread(); // If the thread is not alive, or if the thread is older than THREAD_TIMEOUT, it must be killed // and removed from the list if (!t.isAlive() || (System.currentTimeMillis() - td.getStartTime() >= (m_iThreadTimeout * 1000))) { killThread(td); m_ThreadList.remove(0); return true; } return false; }
From source file:thingynet.event.EventListenerTest.java
@Test public void stopShouldTerminateEventListenerThread() throws Exception { Thread eventListenerThread = new Thread(eventListener); eventListenerThread.start();/*w w w .j a v a 2 s . co m*/ assertThat(eventListenerThread.isAlive(), is(true)); eventListener.stop(); assertThat(eventListenerThread.isAlive(), is(false)); }
From source file:uk.co.gidley.jmxmonitor.services.ThreadManager.java
private void restartMonitoringGroup(String groupName, Configuration config) throws InterruptedException, InitialisationException { logger.warn("Monitoring Group is dead: {}. Restarting", groupName); // Tidy up/*from w w w. j a v a2 s .co m*/ Thread oldThread = monitoringGroups.get(groupName).getThread(); if (oldThread.isAlive()) { // Problem try to interrupt. This should force an exist oldThread.interrupt(); oldThread.join(5000); if (oldThread.isAlive()) { logger.error("Unable to stop monitor thread {}", groupName); throw new RuntimeException("Unable to stop monitor thread " + groupName); } } monitoringGroups.remove(groupName); // Restart initialiseMonitoringGroup(groupName, config); Thread restartThread = monitoringGroups.get(groupName).getThread(); restartThread.start(); }
From source file:fr.aliasource.index.core.SearchDirector.java
private void runCrawler(ICrawler cw) { if (stopped) { return;/* w w w . ja v a 2 s. c o m*/ } Thread t = null; synchronized (runningCrawlers) { t = runningCrawlers.get(cw.getType()); } if (t == null || !t.isAlive()) { startCrawlThread(cw); } }
From source file:org.archive.mapred.ARCMapRunner.java
protected void cleanup(final Thread thread, final ARCReporter reporter) throws IOException { if (!thread.isAlive()) { return;/*from w ww .jav a2s . c o m*/ } reporter.setStatus("Killing indexing thread " + thread.getName(), true); thread.interrupt(); try { // Give it some time to die. thread.join(1000); } catch (final InterruptedException e) { e.printStackTrace(); } if (thread.isAlive()) { LOG.info(thread.getName() + " will not die"); } }
From source file:org.apache.hupa.server.preferences.InImapUserPreferencesStorage.java
/** * Saves the contacts list in IMAP asynchronously, It is so because of two reasons: * 1.- User processes don't wait for it//w w w . j av a 2 s. c om * 2.- It saves number of save operations, because the method addContact * is called frequently when fetching a folder, so add these contacts are * added to the session list, and a thread is delayed to store * all the block. */ private void saveContactsAsync(User user) { Thread thread = threads.get(user); if (thread == null || !thread.isAlive()) { thread = new SavePreferencesThread(user, MAGIC_SUBJECT_CONTACTS, getContactsHash()); threads.put(user, thread); thread.start(); } }
From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.QueryRetrieveController.java
public synchronized void retrieve(final List<QuerySelection> currentRemoteQuerySelectionList) throws GiftCloudException { // Report an error if a previous thread has not yet completed if (activeThread != null && activeThread.isAlive()) { throw new GiftCloudException(GiftCloudUploaderError.QUERY_RETRIEVE_STILL_IN_PROGRESS); }//from ww w . j a v a 2 s. co m if (currentRemoteQueryInformationModel.isPresent()) { Thread activeThread = new Thread(new RetrieveWorker(currentRemoteQuerySelectionList, currentRemoteQueryInformationModel.get(), uploaderStatusModel, reporter)); activeThread.start(); } else { throw new GiftCloudException(GiftCloudUploaderError.NO_QUERY_OR_QUERY_FAILED); } }
From source file:com.cloudera.recordbreaker.analyzer.FSCrawler.java
/** * Is there an ongoing (running) crawl for the given filesystem? *//*from w ww . j a v a 2 s .co m*/ public CrawlRuntimeStatus isCrawlOngoing(URI fsURI) { long fsId = analyzer.getCreateFilesystem(fsURI, false); if (fsId < 0) { return null; } synchronized (pendingCrawls) { final long crawlid = analyzer.getCreatePendingCrawl(fsId, false); Thread pendingThread = pendingCrawls.get(crawlid); if (pendingThread != null && pendingThread.isAlive()) { synchronized (crawlStatusInfo) { return crawlStatusInfo.get(crawlid); } } return null; } }
From source file:com.aaasec.sigserv.cssigapp.KeyStoreFactory.java
private boolean running(Thread thread) { return (thread != null && thread.isAlive()); }
From source file:org.apache.hadoop.hbase.HBaseClusterTestCase.java
protected void threadDumpingJoin(final Thread t) { if (t == null) { return;/*ww w . j a va2 s.c o m*/ } long startTime = System.currentTimeMillis(); while (t.isAlive()) { try { Thread.sleep(1000); } catch (InterruptedException e) { LOG.info("Continuing...", e); } if (System.currentTimeMillis() - startTime > 60000) { startTime = System.currentTimeMillis(); ReflectionUtils.printThreadInfo(new PrintWriter(System.out), "Automatic Stack Trace every 60 seconds waiting on " + t.getName()); } } }