List of usage examples for java.lang Thread interrupted
public static boolean interrupted()
From source file:org.fseek.simon.swing.util.TreeUtil.java
private static void addFiles(File[] files, final LinkTreeNode root, final DefaultTreeModel model, boolean showFiles, boolean showHidden) { for (int i = 0; i < files.length; i++) { if (Thread.interrupted()) { break; }// w w w . jav a 2s. c om File f = files[i]; if (f.isDirectory() || showFiles == true) { final LinkTreeNode childNode = new DefaultLinkTreeNode(f, new IconChangedListener() { @Override public void iconChanged(final LinkTreeNode node, Icon newIcon) { EventQueue.invokeLater(new Runnable() { @Override public void run() { model.nodeChanged(node); } }); } }); final int index = i; EventQueue.invokeLater(new Runnable() { @Override public void run() { model.insertNodeInto(childNode, root, index); } }); AddChildsThread create = AddChildsThread.create(model, childNode, false, showFiles, showHidden, true); if (create.isAlive() && create.isFake() == false) { create.interrupt(); try { create.join(); create = AddChildsThread.create(model, childNode, false, showFiles, showHidden, true); create.start(); } catch (InterruptedException ex) { return; } } else if (create.isAlive() == false) { create.start(); } } } }
From source file:org.marketcetera.util.misc.ReflectUtilsTest.java
@Test public void instance() throws Exception { assertEquals(1, ((IntObject) (ReflectUtils.getInstance(IntObject.class.getName(), new Class[] { Integer.TYPE }, new Object[] { new Integer(1) }))).getValue()); try {//from w w w .ja va 2 s . c om ReflectUtils.getInstance("NonExistent", null, null); fail(); } catch (ClassNotFoundException ex) { assertFalse(Thread.interrupted()); } try { ReflectUtils.getInstance(IntObject.class.getName(), new Class[] { Integer.TYPE }, new Object[] { new Integer(0) }); fail(); } catch (InvocationTargetException ex) { assertTrue(Thread.interrupted()); assertEquals(I18NInterruptedRuntimeException.class, ex.getCause().getClass()); } }
From source file:com.jaspersoft.jasperserver.export.ImporterImpl.java
protected void process() { Document indexDocument = readIndexDocument(); Element indexRoot = indexDocument.getRootElement(); Properties properties = new Properties(); for (Iterator it = indexRoot.elementIterator(getPropertyElementName()); it.hasNext();) { Element propElement = (Element) it.next(); String propKey = propElement.attribute(getPropertyNameAttribute()).getValue(); Attribute valueAttr = propElement.attribute(getPropertyValueAttribute()); String value = valueAttr == null ? null : valueAttr.getValue(); properties.setProperty(propKey, value); }// www.j a v a2 s. c om input.propertiesRead(properties); Attributes contextAttributes = createContextAttributes(); contextAttributes.setAttribute("sourceJsVersion", properties.getProperty(VERSION_ATTR)); contextAttributes.setAttribute("targetJsVersion", super.getJsVersion()); for (Iterator it = indexRoot.elementIterator(getIndexModuleElementName()); it.hasNext();) { if (Thread.interrupted()) { throw new RuntimeException("Cancelled"); } Element moduleElement = (Element) it.next(); String moduleId = moduleElement.attribute(getIndexModuleIdAttributeName()).getValue(); ImporterModule module = getModuleRegister().getImporterModule(moduleId); if (module == null) { throw new JSException("jsexception.import.module.not.found", new Object[] { moduleId }); } commandOut.debug("Invoking module " + module); contextAttributes.setAttribute("appContext", this.task.getApplicationContext()); ModuleContextImpl moduleContext = new ModuleContextImpl(moduleElement, contextAttributes); module.init(moduleContext); List<String> messages = new ArrayList<String>(); ImportRunMonitor.start(); try { List<String> moduleMessages = module.process(); if (moduleMessages != null) { messages.addAll(moduleMessages); } } finally { ImportRunMonitor.stop(); for (String message : messages) { commandOut.info(message); } } } }
From source file:arena.cron.CronThread.java
public void run() { try {//from w ww.j a va 2s . c o m Thread.sleep(2000); } catch (InterruptedException err) { return; } // LogContext.push("cronThread"); try { log.debug("Beginning cron thread"); if (this.httpClientSource == null) { this.httpClientSource = new JakartaCommonsHttpClientSource(); } boolean interruptedFlag = false; try { CronUtils.sleepUntilNextMinute(System.currentTimeMillis()); } catch (InterruptedException err) { interruptedFlag = true; } while (!interruptedFlag) { long now = CronUtils.getZerothSecondMinuteTimestamp(System.currentTimeMillis()); try { // Perform the url gets String formattedDate = CronUtils.formatDateForPatternCheck(new Date(now)); for (int n = 0; (n < this.jobs.length) && !interruptedFlag; n++) { // Check last exec date is in the past if (this.jobs[n].isReadyForExecution(now, formattedDate)) { this.jobs[n].setLastExecutedDate(new Date(now)); executeJob(this.jobs[n]); } if (Thread.interrupted()) { interruptedFlag = true; } } CronUtils.sleepUntilNextMinute(now); if (Thread.interrupted()) { interruptedFlag = true; } } catch (InterruptedException err) { interruptedFlag = true; continue; } } log.debug("Terminating cron thread"); } finally { // LogContext.pop(); } }
From source file:org.apache.solr.cloud.api.collections.TestHdfsCloudBackupRestore.java
@BeforeClass public static void setupClass() throws Exception { dfsCluster = HdfsTestUtil.setupClass(createTempDir().toFile().getAbsolutePath()); hdfsUri = HdfsTestUtil.getURI(dfsCluster); try {//w w w. j av a2 s .c om URI uri = new URI(hdfsUri); Configuration conf = HdfsTestUtil.getClientConfiguration(dfsCluster); conf.setBoolean("fs.hdfs.impl.disable.cache", true); fs = FileSystem.get(uri, conf); if (fs instanceof DistributedFileSystem) { // Make sure dfs is not in safe mode while (((DistributedFileSystem) fs).setSafeMode(SafeModeAction.SAFEMODE_GET, true)) { log.warn("The NameNode is in SafeMode - Solr will wait 5 seconds and try again."); try { Thread.sleep(5000); } catch (InterruptedException e) { Thread.interrupted(); // continue } } } fs.mkdirs(new org.apache.hadoop.fs.Path("/backup")); } catch (IOException | URISyntaxException e) { throw new RuntimeException(e); } System.setProperty("solr.hdfs.default.backup.path", "/backup"); System.setProperty("solr.hdfs.home", hdfsUri + "/solr"); useFactory("solr.StandardDirectoryFactory"); configureCluster(NUM_SHARDS)// nodes .addConfig("conf1", TEST_PATH().resolve("configsets").resolve("cloud-minimal").resolve("conf")) .withSolrXml(SOLR_XML).configure(); }
From source file:com.arpnetworking.tsdcore.sinks.PeriodicStatisticsSink.java
/** * {@inheritDoc}/*from ww w.j a v a 2s .c om*/ */ @Override public void close() { try { _executor.shutdown(); _executor.awaitTermination(EXECUTOR_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS); } catch (final InterruptedException e) { Thread.interrupted(); throw Throwables.propagate(e); } flushMetrics(_metrics.get()); }
From source file:jenkins.plugins.itemstorage.s3.S3UploadAllCallable.java
private void waitForUploads(AtomicInteger count, Uploads uploads) { count.addAndGet(uploads.count());/*www.java2 s. c om*/ try { uploads.finishUploading(); } catch (InterruptedException ie) { // clean up and bomb out uploads.cleanup(); Thread.interrupted(); } }
From source file:interactivespaces.util.concurrency.AcceptingPriorityEventQueue.java
/** * Process events until the event processing thread is interrupted. *//*from ww w .j a v a 2s. co m*/ private void processEvents() { try { while (!Thread.interrupted()) { processNextEvent(); } } catch (InterruptedException e) { // Don't care } }
From source file:org.forgerock.openam.cts.reaper.CTSReaper.java
/** * Performs the query against the directory by selecting the Token IDs for all Tokens * that have expired. These Token IDs are then scheduled for deletion. The task will * not complete until all of the delete operations have returned. *///from ww w .j a va 2s . c om public void run() { // Timers for debugging StopWatch query = new StopWatch(); StopWatch waiting = new StopWatch(); // Latches will track each page of results List<CountDownLatch> latches = new ArrayList<CountDownLatch>(); // Create the query against the directory calendar.setTimeInMillis(System.currentTimeMillis()); Filter expired = factory.createFilter().and().beforeDate(calendar).build(); QueryBuilder queryBuilder = factory.createInstance().withFilter(expired) .returnTheseAttributes(CoreTokenField.TOKEN_ID); QueryPageIterator iterator = new QueryPageIterator(queryBuilder, config.getCleanupPageSize()); query.start(); long total = 0; try { // Iterate over the result pages while (iterator.hasNext()) { Collection<Entry> entries = iterator.next(); total += entries.size(); // If the thread has been interrupted, exit all processing. if (Thread.interrupted()) { return; } // Latch will track the deletions of the page CountDownLatch latch = new CountDownLatch(entries.size()); DeleteComplete complete = new DeleteComplete(latch); latches.add(latch); // Delete the tokens. try { tokenDeletion.deleteBatch(entries, complete); } catch (ErrorResultException e) { debug.error("Failed to get a connection, will retry later", e); return; } if (debug.messageEnabled()) { debug.message(MessageFormat .format(CoreTokenConstants.DEBUG_HEADER + "Reaper: Queried {0} Tokens", total)); } } query.stop(); waiting.start(); if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Reaper: Expired Token Query Time: {0}ms", query.getTime())); } // Wait stage for (CountDownLatch latch : latches) { try { latch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } waiting.stop(); if (debug.messageEnabled()) { debug.message(MessageFormat.format( CoreTokenConstants.DEBUG_HEADER + "Reaper: Worker threads Time: {0}ms", waiting.getTime())); } } finally { // Once all latches are complete, close the TokenDeletion IOUtils.closeIfNotNull(tokenDeletion); } }
From source file:com.boylesoftware.web.AsynchronousExecutor.java
@Override public void run() { Thread.interrupted(); this.executorThread = Thread.currentThread(); final boolean debug = this.log.isDebugEnabled(); if (debug)//from w w w .ja v a2s . c o m this.log.debug("started async executor for request " + this.routerReq + (this.routerReq != null ? " [" + this.routerReq.getRequestURI() + "]" : "")); try { this.checkTimeout(); this.execute(); } catch (final TimeOutException e) { if (debug) this.log.debug("timeout", e); } catch (final Exception e) { if (debug) this.log.debug("error in async executor", e); try { Router.setAsyncException(this.routerReq, e); if (debug) this.log.debug("dispatching back to the router"); this.asyncContext.dispatch(); } catch (final Exception e1) { if (debug) this.log.debug("error dispatching async executor error" + " back to the router", e1); } } finally { if (debug) this.log.debug("exiting async executor"); } }