happytimor opened a new issue, #10188:
URL: https://github.com/apache/dubbo/issues/10188
最近开发一个类似流程任务的一个功能, 核心就是在线程池里运行任务, 代码如下:
```java
RUNNER_EXECUTOR.execute(() -> {
pipelineService.startTask(taskId);
});
```
后来业务需要进行支持中断操作, 于是调整代码如下:
``` java
//启动逻辑
Future<?> future = this.RUNNER_EXECUTOR.submit(() -> {
this.pipelineService.startTask(taskId);
});
TASK_FUTURE_MAP.put(taskId, future);
```
```java
//中断逻辑
TASK_FUTURE_MAP.remove(taskId).cancel(true);
```
运行后发现任务无法被中断,查了下,发现最终是因为startTask方法里面的dubbo调用有设置重试次数(大部分时间是需要重试),failover策略会把InterruptException当做普通异常,直接重试了(打断失败)。
我觉得应该把InterruptException直接抛出来, 于是做了一个pr如下:
https://github.com/apache/dubbo/pull/10164
``` java
//Brief code
public Result doInvoke(Invocation invocation, final List<Invoker<T>>
invokers, LoadBalance loadbalance) {
for (int i = 0; i < len; i++) {
try {
Result result = invoker.invoke(invocation);
return result;
} catch (RpcException e) {
if (e.isBiz()) {
throw e;
}
//merge code start
if
(e.getCause().toString().equals(InterruptedException.class.getName())) {
throw new RuntimeException(e);
}
//merge code end
le = e;
} catch (Throwable e) {
le = new RpcException(e.getMessage(), e);
} finally {
providers.add(invoker.getUrl().getAddress());
}
}
throw new RpcException();
```
想问下:
1. 这个pr有没有合并价值
2. 如果不这么做的话,怎么实现我的中断需求比较合理
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]