Skip to content

为什么Handler中可以使用异步而Filter中不行了? #2091

@xhanthow

Description

@xhanthow

我在Handler中使用了CompletableFuture,代码如下:

public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
	SomeTask task = new SomeTask(completableFuture);
	ThreadPoolUtil.getInstance().execute(task);
	completableFuture.whenComplete((res, ex) -> {
		try {
			afterCheckRights(res, asyncResp, invocation);
		} catch (Throwable e) {
			asyncResp.consumerFail(new InvocationException(Status.BAD_GATEWAY, e.getMessage()));
		}
	});
}

private void afterCheckRights(String res, AsyncResponse asyncResp, Invocation invocation) throws Exception {
	// 发现这里切换了线程,之前是eventloop的,现在是自己定义的线程池,这样有什么影响吗?
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions