java - 如何使Java(AppEngine)中的延迟任务在失败时不重复?

标签 java google-app-engine

我阅读了谷歌文档,但只有关于非延迟任务的说法。在那里我们创建带有参数的 xml 文件,并可以指定重试次数。

但我使用延迟任务:

public static class ExpensiveOperation implements DeferredTask
{
  @Override
  public void run()
  {
    System.out.println("Doing an expensive operation...");
    // expensive operation to be backgrounded goes here
  }
}

并以这种方式创建它:

Queue queue = QueueFactory.getDefaultQueue();         
queue.add(TaskOptions.Builder.withPayload(new ExpensiveOperation(/*different params*/)));

如何指定我不希望它在失败时重新启动?

最佳答案

我不是 Java 用户,但我在 Interface DeferredTask 中看到了这一点我认为您可以使用:

Normal return from this method is considered success and will not retry unless DeferredTaskContext.markForRetry() is called. Exceptions thrown from this method will indicate a failure and will be processed as a retry attempt unless DeferredTaskContext.setDoNotRetry(boolean) was set to true.

关于java - 如何使Java(AppEngine)中的延迟任务在失败时不重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46805776/

相关文章:

java - 如何在 OpenScript 中获取结果文件夹的当前 session 数?

Java 数组 - 它们是什么

java - 如何在 Eclipse 中导入 com.google.cloud.datastore?

google-app-engine - 通过 Google App Engine 数据存储查看器删除实体不会从内存缓存中删除实体

java - 转到 TextView 时与旋转器相关的问题

java - 指向桌面 (Java) 和发布程序的定向路径

java - JAXB/Jersey - JSONObject 作为 XmlElement

google-app-engine - Google App Engine 中的默认文档

google-app-engine - 谷歌应用引擎 : Budget and Daily Spending Limit not Working

python - 如何在Python中从表单中传递参数