本文整理匯總了Java中java.util.concurrent.FutureTask.cancel方法的典型用法代碼示例。如果您正苦於以下問題:Java FutureTask.cancel方法的具體用法?Java FutureTask.cancel怎麽用?Java FutureTask.cancel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.FutureTask
的用法示例。
在下文中一共展示了FutureTask.cancel方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: eval
import java.util.concurrent.FutureTask; //導入方法依賴的package包/類
public Map<String, Object> eval(String script, IMessage message) {
Map<String, Object> resultMap = new LinkedHashMap<>();
Map<String, Object> scope = new LinkedHashMap<>();
resultMap.put("script", script);
resultMap.put("startedAt", ZonedDateTime.now());
scope.put("bot", message.getClient().getOurUser());
scope.put("client", message.getClient());
scope.put("message", message);
scope.put("content", message.getContent());
scope.put("guild", message.getChannel().isPrivate() ? null : message.getChannel().getGuild());
scope.put("channel", message.getChannel());
scope.put("author", message.getAuthor());
FutureTask<String> evalTask = new FutureTask<>(() -> evalWithScope(script, scope));
try {
CompletableFuture.runAsync(evalTask);
resultMap.put("result", evalTask.get(1, TimeUnit.MINUTES));
} catch (Throwable t) {
log.error("Could not bind result", t);
resultMap.put("throwable", t);
resultMap.put("error", t.getMessage());
evalTask.cancel(true);
}
resultMap.put("stoppedAt", ZonedDateTime.now());
return resultMap;
}
示例2: checkAndMarkRunningHbck
import java.util.concurrent.FutureTask; //導入方法依賴的package包/類
/**
* This method maintains a lock using a file. If the creation fails we return null
*
* @return FSDataOutputStream object corresponding to the newly opened lock file
* @throws IOException
*/
private FSDataOutputStream checkAndMarkRunningHbck() throws IOException {
RetryCounter retryCounter = lockFileRetryCounterFactory.create();
FileLockCallable callable = new FileLockCallable(retryCounter);
ExecutorService executor = Executors.newFixedThreadPool(1);
FutureTask<FSDataOutputStream> futureTask = new FutureTask<FSDataOutputStream>(callable);
executor.execute(futureTask);
final int timeoutInSeconds = getConf().getInt(
"hbase.hbck.lockfile.maxwaittime", DEFAULT_WAIT_FOR_LOCK_TIMEOUT);
FSDataOutputStream stream = null;
try {
stream = futureTask.get(timeoutInSeconds, TimeUnit.SECONDS);
} catch (ExecutionException ee) {
LOG.warn("Encountered exception when opening lock file", ee);
} catch (InterruptedException ie) {
LOG.warn("Interrupted when opening lock file", ie);
Thread.currentThread().interrupt();
} catch (TimeoutException exception) {
// took too long to obtain lock
LOG.warn("Took more than " + timeoutInSeconds + " seconds in obtaining lock");
futureTask.cancel(true);
} finally {
executor.shutdownNow();
}
return stream;
}
示例3: actionPerformed
import java.util.concurrent.FutureTask; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
setEnabled(false); // discourage repeated clicking
FutureTask<DockerImage> actionTask;
synchronized (this) {
actionTask = task;
}
if (actionTask != null) {
actionTask.cancel(true);
}
}
示例4: cancel
import java.util.concurrent.FutureTask; //導入方法依賴的package包/類
static <V> void cancel(FutureTask<V> task, boolean mayInterruptIfRunning) {
task.cancel(mayInterruptIfRunning);
checkCancelled(task);
}