List of usage examples for java.lang InterruptedException getCause
public synchronized Throwable getCause()
From source file:org.acmsl.queryj.tools.handlers.JdbcConnectionClosingHandler.java
/** * Waits until all generation threads have finish. * @param tasks the tasks.//from w w w . ja v a2s. c o m * @param log the {@link Log} instance. */ protected void waitUntilGenerationThreadsFinish( @NotNull final List<Future<? extends QueryJTemplate<QueryJTemplateContext>>> tasks, @Nullable final Log log) { for (@Nullable final Future<? extends QueryJTemplate<QueryJTemplateContext>> t_Task : tasks) { if (t_Task != null) { while (!t_Task.isDone()) { try { if (log != null) { log.debug("Waiting for " + t_Task.get().getTemplateContext().getTemplateName() + " to finish"); } } catch (@NotNull final InterruptedException interrupted) { log.info(INTERRUPTED_WHILE_WAITING_FOR_THE_THREADS_TO_FINISH, interrupted); } catch (@NotNull final ExecutionException interrupted) { log.info(interrupted.getMessage()); Throwable cause = interrupted.getCause(); while (cause != null) { log.error(cause.getMessage(), cause); cause = cause.getCause(); } } synchronized (LOCK) { try { LOCK.wait(1000); } catch (@NotNull final InterruptedException interrupted) { if (log != null) { log.info(INTERRUPTED_WHILE_WAITING_FOR_THE_THREADS_TO_FINISH, interrupted); } } } } } } }
From source file:org.atomserver.ThrottledAtomServer.java
/** * Execute the CallableTask on a ThreadPoolTaskExecutor. <br/> * NOTE: the standard Exception handling of AtomServer still happens in the AtomServer class. * Any Exception handling done here is for Exceptions that actually are thrown this far up * the food chain -- Exceptions that pertain directly to the TaskExecutor -- * for example, TimeoutException or ExecutionException. * * @param request The Abdera RequestContext * @param callableTask The CallableTask, which shoudl just be a wrapped call to * the corresponding super task. * @return The Abdera ResponseContext/* www.j a v a 2 s . c o m*/ */ private ResponseContext executePooledTask(final RequestContext request, final Callable<ResponseContext> callableTask) { ResponseContext response = null; Abdera abdera = request.getServiceContext().getAbdera(); try { FutureTask<ResponseContext> futureTask = new FutureTask(callableTask); threadPool.execute(futureTask); try { logger.debug("starting to wait for the task to complete"); response = futureTask.get(taskTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { // InterruptedException - if the current thread was interrupted while waiting // Re-assert the thread's interrupted status Thread.currentThread().interrupt(); logger.error("InterruptedException in executePooledTask: Cause= " + e.getCause() + " Message= " + e.getMessage(), e); return getAtomServer().servererror(abdera, request, "InterruptedException occurred:: " + e.getCause(), e); } catch (ExecutionException e) { // ExecutionException - if the computation threw an exception // Because all Exception handling is done in the super class; AtomServer, we should never get this logger.error("ExecutionException in executePooledTask: Cause= " + e.getCause() + " Message= " + e.getMessage(), e); return getAtomServer().servererror(abdera, request, "ExecutionException occurred:: " + e.getCause(), e); } catch (TimeoutException e) { // TimeoutException - if the wait timed out logger.error("TimeoutException in executePooledTask: Cause= " + e.getCause() + " Message= " + e.getMessage(), e); return getAtomServer().servererror(abdera, request, "TimeoutException occurred:: " + e.getCause(), e); } catch (Exception e) { logger.error("Unknown Exception in executePooledTask: Cause= " + e.getCause() + " Message= " + e.getMessage(), e); return getAtomServer().servererror(abdera, request, "Unknown Exception occurred:: " + e.getCause(), e); } finally { // Best practice is to cancel tasks whose result is no longer needed // NOTE; task.cancel() is harmless if the task has already completed // Interrupt if running... futureTask.cancel(true); // Help out the garbage collector futureTask = null; } } finally { // Log all thread pool statistics at INFO level. // This information is very critical in understanding the effectiveness of the pool logThreadPoolStats(); } return response; }
From source file:com.alexnederlof.jasperreport.JasperReporter.java
private void executeTasks(List<CompileTask> tasks) throws MojoExecutionException { try {/*from w w w. java 2s . c o m*/ long t1 = System.currentTimeMillis(); List<Future<Void>> output = Executors.newFixedThreadPool(numberOfThreads).invokeAll(tasks); long time = (System.currentTimeMillis() - t1); log.info("Generated " + output.size() + " jasper reports in " + (time / 1000.0) + " seconds"); checkForExceptions(output); } catch (InterruptedException e) { log.error("Failed to compile Japser reports: Interrupted!", e); throw new MojoExecutionException("Error while compiling Jasper reports", e); } catch (ExecutionException e) { if (e.getCause() instanceof JRException) { throw new MojoExecutionException(ERROR_JRE_COMPILE_ERROR, e); } else { throw new MojoExecutionException("Error while compiling Jasper reports", e); } } }
From source file:org.drools.planner.benchmark.core.DefaultPlannerBenchmark.java
protected void runSingleBenchmarks() { Map<SingleBenchmark, Future<SingleBenchmark>> futureMap = new HashMap<SingleBenchmark, Future<SingleBenchmark>>(); for (ProblemBenchmark problemBenchmark : unifiedProblemBenchmarkList) { for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { Future<SingleBenchmark> future = executorService.submit(singleBenchmark); futureMap.put(singleBenchmark, future); }//from w w w. jav a 2s. c o m } // wait for the benchmarks to complete for (Map.Entry<SingleBenchmark, Future<SingleBenchmark>> futureEntry : futureMap.entrySet()) { SingleBenchmark singleBenchmark = futureEntry.getKey(); Future<SingleBenchmark> future = futureEntry.getValue(); Throwable failureThrowable = null; try { // Explicitly returning it in the Callable guarantees memory visibility singleBenchmark = future.get(); // TODO WORKAROUND Remove when JBRULES-3462 is fixed. if (singleBenchmark.getScore() == null) { throw new IllegalStateException("Score is null. TODO fix JBRULES-3462."); } } catch (InterruptedException e) { logger.error("The singleBenchmark (" + singleBenchmark.getName() + ") was interrupted.", e); failureThrowable = e; } catch (ExecutionException e) { Throwable cause = e.getCause(); logger.error("The singleBenchmark (" + singleBenchmark.getName() + ") failed.", cause); failureThrowable = cause; } catch (IllegalStateException e) { // TODO WORKAROUND Remove when JBRULES-3462 is fixed. logger.error("The singleBenchmark (" + singleBenchmark.getName() + ") failed.", e); failureThrowable = e; } if (failureThrowable == null) { singleBenchmark.setSucceeded(true); } else { singleBenchmark.setSucceeded(false); singleBenchmark.setFailureThrowable(failureThrowable); failureCount++; if (firstFailureThrowable == null) { firstFailureThrowable = failureThrowable; } } } }
From source file:org.springframework.integration.etcd.leader.LeaderInitiator.java
/** * Notifies that the candidate's leadership was revoked. * @throws InterruptedException if the current thread was interrupted while waiting for the worker * thread to finish.//from w ww . ja va 2 s . c o m */ private void notifyRevoked() throws InterruptedException { this.isLeader = false; this.leaderEventPublisher.publishOnRevoked(LeaderInitiator.this, this.context, this.candidate.getRole()); this.workerFuture.cancel(true); try { this.workerFuture.get(); } catch (InterruptedException e) { throw e; } catch (CancellationException e) { // Consume } catch (ExecutionException e) { logger.error("Exception thrown by candidate", e.getCause()); } }
From source file:com.anrisoftware.mongoose.environment.EnvironmentImpl.java
@Override public void executeCommandAndWait(Command command) throws CommandException { Future<Command> task = threads.submit(command); try {/*from www.ja v a 2 s .c o m*/ task.get(); } catch (InterruptedException e) { throw log.commandInterrupted(e, command); } catch (java.util.concurrent.ExecutionException e) { throw log.commandError(e.getCause(), command); } catch (CancellationException e) { throw log.commandCanceled(e, command); } }
From source file:org.copperengine.core.persistent.cassandra.CassandraStorage.java
private SettableFuture<Void> createSettableFuture(final ResultSetFuture rsf, final String mpId, final long startTsNanos) { final SettableFuture<Void> rv = SettableFuture.create(); rsf.addListener(new Runnable() { @Override//from w w w. j ava 2 s . c om public void run() { try { runtimeStatisticsCollector.submit(mpId, 1, System.nanoTime() - startTsNanos, TimeUnit.NANOSECONDS); rsf.get(); rv.set(null); } catch (InterruptedException e) { rv.setException(e); } catch (ExecutionException e) { rv.setException(e.getCause()); } } }, executor); return rv; }
From source file:com.univocity.app.swing.DataAnalysisWindow.java
protected void executeProcess(String processName) { final Runnable process = config.getProcess(processName); getGlass().activate("Executing process: '" + processName + "'..."); Thread thread = new Thread() { @Override//from ww w . j a v a 2 s. c o m public void run() { try { long start = System.currentTimeMillis(); SwingUtilities.invokeAndWait(process); long timeTaken = System.currentTimeMillis() - start; setStatus("Completed.", "Took " + timeTaken / 1000 + " seconds (" + timeTaken + " ms)"); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); setStatus("Interrupted", ""); } catch (InvocationTargetException ie) { WindowUtils.showErrorMessage(DataAnalysisWindow.this, ie.getCause()); setStatus("Interrupted", ""); } finally { getGlass().deactivate(); } System.gc(); } }; thread.start(); }
From source file:bear.core.SessionContext.java
public TaskResult<?> getPreviousResult(String taskDefName) { try {//from w w w . j ava2 s.c o m return globalRunner.future(taskDefName, getName()).get(); } catch (InterruptedException e) { throw new IllegalStateException("future must be completed when retrieving result in the same session"); } catch (ExecutionException e) { throw Exceptions.runtime(e.getCause()); } }
From source file:com.reactivetechnologies.analytics.core.handlers.ModelCombinerComponent.java
/** * Runs a cluster wide model collection, and generates a combined (ensembled/voted/evaluated) classifier model. * The generated model is persisted in database, only if it is different than the ones already present. * @return Persisted model Id, or "" if not persisted in this run * @throws EngineException// w ww. jav a 2 s. c om */ public CombinerResult runTask() throws EngineException { log.info("[ensembleModelTask] task starting.."); String modelId = ""; CombinerResult result = CombinerResult.IGNORED; try { boolean done = tryMemberSnapshot(10, TimeUnit.MINUTES); if (done) { modelId = ensembleModels(); if (modelId != null) { result = CombinerResult.MODEL_CREATED; result.setModelId(modelId); } } else { log.info("[ensembleModelTask] task ignored.. "); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); log.debug("", e); } catch (TimeoutException e) { log.warn("[ensembleModelTask] task timed out. Generated model may be inconsistent", e); result = CombinerResult.MODEL_CREATED; } catch (EngineException e) { if (e.getCause() instanceof DuplicateKeyException) { log.warn(e.getMessage()); //log.debug(e.getMessage(), e.getCause()); result = CombinerResult.MODEL_EXISTS; result.setModelId(e.getCause().getMessage()); } else throw e; } return result; }