Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cse2.x 的handler 线程安全吗? #4642

Open
huxiaozheng opened this issue Dec 13, 2024 · 1 comment
Open

cse2.x 的handler 线程安全吗? #4642

huxiaozheng opened this issue Dec 13, 2024 · 1 comment
Labels

Comments

@huxiaozheng
Copy link

业务最近拓展了handler,并在handler里将一个hashmap存在invocation里。然后将此handler放到了consumer下。我们压测A微服务调B微服务,我们发现,A微服务在上述新增handler里存入hashmap后,在clientFilter里偶现取不到这个hashmap里的某些value。我们怀疑这个hashmap被其他线程改了,将hashmap改为concurrentHashMap后,问题解决。请问下,并发场景下,这个handler是被所有线程持有共享,还是每个线程单独持有的?

@liubao68
Copy link
Contributor

public interface Handler {
  void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception;
}

handler是会被多线程访问的,需要业务保证线程安全。 Invocation是关联某个请求的,只会被这个请求的执行流程访问,也就是不会出现多线程的情况。

可能需要你提供一个简单的DEMO描述下你的场景,才能理解你的问题。

@liubao68 liubao68 added the 2.x label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants