java.util.concurrent.FutureTask#isCancelled ( )源码实例Demo

下面列出了java.util.concurrent.FutureTask#isCancelled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hadoop   文件: DeletionService.java
@Override
protected void afterExecute(Runnable task, Throwable exception) {
  if (task instanceof FutureTask<?>) {
    FutureTask<?> futureTask = (FutureTask<?>) task;
    if (!futureTask.isCancelled()) {
      try {
        futureTask.get();
      } catch (ExecutionException ee) {
        exception = ee.getCause();
      } catch (InterruptedException ie) {
        exception = ie;
      }
    }
  }
  if (exception != null) {
    LOG.error("Exception during execution of task in DeletionService",
      exception);
  }
}
 
源代码2 项目: bt   文件: NonblockingScheduledExecutor.java
@Override
protected void afterExecute(Runnable r, Throwable t) {
	super.afterExecute(r, t);
	
	if(exceptionHandler != null && r instanceof FutureTask<?>) {
		FutureTask<?> ft = (FutureTask<?>) r;
		if(ft.isDone() && !ft.isCancelled()) {
			try {
				ft.get();
			} catch (InterruptedException | ExecutionException e) {
				exceptionHandler.uncaughtException(null, e.getCause());
			}
		}
		
	}
}
 
源代码3 项目: bt   文件: LoggingScheduledThreadPoolExecutor.java
@Override
protected void afterExecute(Runnable r, Throwable t) {
	super.afterExecute(r, t);
	
	if(r instanceof FutureTask<?>) {
		FutureTask<?> ft = (FutureTask<?>) r;
		if(ft.isDone() && !ft.isCancelled()) {
			try {
				ft.get();
			} catch (InterruptedException | ExecutionException e) {
				exceptionHandler.accept(e.getCause());
			}
		}
		
		if(t != null)
			exceptionHandler.accept(t);
		
	}
}
 
源代码4 项目: big-c   文件: DeletionService.java
@Override
protected void afterExecute(Runnable task, Throwable exception) {
  if (task instanceof FutureTask<?>) {
    FutureTask<?> futureTask = (FutureTask<?>) task;
    if (!futureTask.isCancelled()) {
      try {
        futureTask.get();
      } catch (ExecutionException ee) {
        exception = ee.getCause();
      } catch (InterruptedException ie) {
        exception = ie;
      }
    }
  }
  if (exception != null) {
    LOG.error("Exception during execution of task in DeletionService",
      exception);
  }
}
 
源代码5 项目: mldht   文件: NonblockingScheduledExecutor.java
@Override
protected void afterExecute(Runnable r, Throwable t) {
	super.afterExecute(r, t);
	
	if(exceptionHandler != null && r instanceof FutureTask<?>) {
		FutureTask<?> ft = (FutureTask<?>) r;
		if(ft.isDone() && !ft.isCancelled()) {
			try {
				ft.get();
			} catch (InterruptedException | ExecutionException e) {
				exceptionHandler.uncaughtException(null, e.getCause());
			}
		}
		
	}
}
 
@Override
protected void afterExecute(Runnable r, Throwable t) {
	super.afterExecute(r, t);
	
	if(r instanceof FutureTask<?>) {
		FutureTask<?> ft = (FutureTask<?>) r;
		if(ft.isDone() && !ft.isCancelled()) {
			try {
				ft.get();
			} catch (InterruptedException | ExecutionException e) {
				exceptionHandler.accept(e.getCause());
			}
		}
		
		if(t != null)
			exceptionHandler.accept(t);
		
	}
}
 
@Override
@NotNull
public FutureTask<Boolean> preprocessFile(@NotNull PsiFile file, boolean processChangedTextOnly) throws IncorrectOperationException {
    final FutureTask<Boolean> reformatTask = myReformatCodeProcessor.preprocessFile(file, processChangedTextOnly);
    final FutureTask<Boolean> optimizeImportsTask = myOptimizeImportsProcessor.preprocessFile(file, false);
    return new FutureTask<Boolean>(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            reformatTask.run();
            if (!reformatTask.get() || reformatTask.isCancelled()) {
                return false;
            }

            CodeStyleManagerImpl.setSequentialProcessingAllowed(false);
            try {
                optimizeImportsTask.run();
                return optimizeImportsTask.get() && !optimizeImportsTask.isCancelled();
            }
            finally {
                CodeStyleManagerImpl.setSequentialProcessingAllowed(true);
            }
        }
    });
}
 
源代码8 项目: consulo   文件: AbstractLayoutCodeProcessor.java
public FutureTask<Boolean> preprocessFile(@Nonnull PsiFile file, boolean processChangedTextOnly) throws IncorrectOperationException {
  final FutureTask<Boolean> previousTask = getPreviousProcessorTask(file, processChangedTextOnly);
  final FutureTask<Boolean> currentTask = prepareTask(file, processChangedTextOnly);

  return new FutureTask<>(() -> {
    try {
      if (previousTask != null) {
        previousTask.run();
        if (!previousTask.get() || previousTask.isCancelled()) return false;
      }

      ApplicationManager.getApplication().runWriteAction(currentTask);

      return currentTask.get() && !currentTask.isCancelled();
    }
    catch (ExecutionException e) {
      ExceptionUtil.rethrowUnchecked(e.getCause());
      throw e;
    }
  });
}
 
源代码9 项目: ans-android-sdk   文件: AThreadPool.java
/**
 * 高优先级同步执行:主要时get类对外操作接口
 *
 * @param callable
 * @return
 */
public static Object syncHighPriorityExecutor(Callable callable) {
    Object object = null;
    FutureTask<Object> futureTask = new FutureTask<Object>(callable);
    highService.execute(futureTask);

    while (!futureTask.isDone() && !futureTask.isCancelled()) {
        try {
            object = futureTask.get();
        } catch (Throwable ignore) {
            ExceptionUtil.exceptionThrow(ignore);
        }
    }
    return object;
}
 
源代码10 项目: smallrye-fault-tolerance   文件: FutureExecution.java
@Override
public Future<V> apply(InvocationContext<Future<V>> ctx) {
    FutureTask<Future<V>> task = new NamedFutureTask<>("FutureExecution", () -> delegate.apply(ctx));
    executor.execute(task);
    return new Future<V>() {
        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            ctx.fireEvent(CancellationEvent.INSTANCE);
            return task.cancel(mayInterruptIfRunning);
        }

        @Override
        public boolean isCancelled() {
            return task.isCancelled();
        }

        @Override
        public boolean isDone() {
            return task.isDone();
        }

        @Override
        public V get() throws InterruptedException, ExecutionException {
            return task.get().get();
        }

        @Override
        public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
            // at worst, the timeout here could possibly be 2x the requested value
            return task.get(timeout, unit).get(timeout, unit);
        }
    };
}
 
源代码11 项目: localization_nifi   文件: FlowEngine.java
/**
 * Hook method called by the thread that executed the given runnable after execution of the runnable completed. Logs the fact of completion and any errors that might have occurred.
 *
 * @param runnable runnable
 * @param throwable throwable
 */
@Override
protected void afterExecute(final Runnable runnable, final Throwable throwable) {
    super.afterExecute(runnable, throwable);
    if (runnable instanceof FutureTask<?>) {
        final FutureTask<?> task = (FutureTask<?>) runnable;
        try {
            if (task.isDone()) {
                if (task.isCancelled()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("A flow controller execution task '{}' has been cancelled.", runnable);
                    }
                } else {
                    task.get(); //to raise any exceptions that might have occurred.
                    logger.debug("A Flow Controller execution task '{}' has completed.", runnable);
                }
            }
        } catch (final CancellationException ce) {
            if (logger.isDebugEnabled()) {
                logger.debug("A flow controller execution task '{}' has been cancelled.", runnable);
            }
        } catch (final InterruptedException ie) {
            if (logger.isDebugEnabled()) {
                logger.debug("A flow controller execution task has been interrupted.", ie);
            }
        } catch (final ExecutionException ee) {
            logger.error("A flow controller task execution stopped abnormally", ee);
        }
    } else {
        logger.debug("A flow controller execution task '{}' has finished.", runnable);
    }
}
 
源代码12 项目: nifi   文件: FlowEngine.java
/**
 * Hook method called by the thread that executed the given runnable after execution of the runnable completed. Logs the fact of completion and any errors that might have occurred.
 *
 * @param runnable runnable
 * @param throwable throwable
 */
@Override
protected void afterExecute(final Runnable runnable, final Throwable throwable) {
    super.afterExecute(runnable, throwable);
    if (runnable instanceof FutureTask<?>) {
        final FutureTask<?> task = (FutureTask<?>) runnable;
        try {
            if (task.isDone()) {
                if (task.isCancelled()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("A flow controller execution task '{}' has been cancelled.", runnable);
                    }
                } else {
                    task.get(); //to raise any exceptions that might have occurred.
                    logger.debug("A Flow Controller execution task '{}' has completed.", runnable);
                }
            }
        } catch (final CancellationException ce) {
            if (logger.isDebugEnabled()) {
                logger.debug("A flow controller execution task '{}' has been cancelled.", runnable);
            }
        } catch (final InterruptedException ie) {
            if (logger.isDebugEnabled()) {
                logger.debug("A flow controller execution task has been interrupted.", ie);
            }
        } catch (final ExecutionException ee) {
            logger.error("A flow controller task execution stopped abnormally", ee);
        }
    } else {
        logger.debug("A flow controller execution task '{}' has finished.", runnable);
    }
}
 
源代码13 项目: beakerx   文件: BeakerCellExecutor.java
private TryResult getResult(FutureTask<TryResult> ret) {
  TryResult o;
  try {
    o = ret.get();
  } catch (Exception e) {
    e.printStackTrace();
    return TryResult.createError(e.getMessage());
  }

  if (ret.isCancelled())
    return TryResult.createError("Cancelled");
  return o;
}
 
源代码14 项目: consulo   文件: AbstractLayoutCodeProcessor.java
private void checkStop(FutureTask<Boolean> task, PsiFile file) {
  try {
    if (!task.get() || task.isCancelled()) {
      myStopFormatting = true;
    }
  }
  catch (InterruptedException | ExecutionException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IndexNotReadyException) {
      LOG.warn(cause);
      return;
    }
    LOG.error("Got unexpected exception during formatting " + file, e);
  }
}
 
源代码15 项目: openjdk-jdk9   文件: Customized.java
static <V> void run(FutureTask<V> task) {
    boolean isCancelled = task.isCancelled();
    task.run();
    check(task.isDone());
    equal(isCancelled, task.isCancelled());
}