0

假设以下代码片段:

TStream<Integer> stream = top.generate(() -> {            
  try{
    Thread.sleep(1500);
  }catch(InterruptedException ex){
    //DO NOTHING
  }
  return (int)(Math.random() * 100);
});

TWindow<Integer, Integer> window = stream.last(5, TimeUnit.SECONDS, zero());

TStream<Double> average = window.batch((values, key) -> {
  int sum = values.stream().mapToInt(Integer::intValue).sum();
  return (double)sum / values.size();
});

average.peek(average1 -> LOGGER.info("Calculated average : " + average1));
job = dp.submit(top);

调用后job = dp.submit(top),执行拓扑的线程将继续在后台运行,直到 JVM 停止。

如何以编程方式停止此后台进程?当 Edgent 拓扑作为单独的进程与同一 JVM 中的其他任务一起运行时,这特别有用。我试图打电话job.cancel(true),但这并不能解决问题。任务继续运行...

4

1 回答 1

1

尝试通过关闭作业Job.stateChange(Job.Action.CLOSE)

在此处查看示例使用: https ://github.com/apache/incubator-edgent-samples/blob/develop/topology/src/main/java/org/apache/edgent/samples/topology/JobExecution.java

于 2018-06-27T14:37:08.483 回答