當前位置: 首頁>>代碼示例>>Java>>正文


Java FutureTask.cancel方法代碼示例

本文整理匯總了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;
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:26,代碼來源:ScriptService.java

示例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;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:HBaseFsck.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:BuildImageWizard.java

示例4: cancel

import java.util.concurrent.FutureTask; //導入方法依賴的package包/類
static <V> void cancel(FutureTask<V> task, boolean mayInterruptIfRunning) {
    task.cancel(mayInterruptIfRunning);
    checkCancelled(task);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:Customized.java


注:本文中的java.util.concurrent.FutureTask.cancel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。