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

使用TransmittableThreadLocal<HashMap>出现ConcurrentModificationException #677

Closed
luocunhao opened this issue Jul 24, 2024 · 1 comment
Assignees
Labels
❓question Further information is requested

Comments

@luocunhao
Copy link

luocunhao commented Jul 24, 2024

InheritableThreadLocal<Map<String, String>> logTagsLocal = TransmittableThreadLocal.withInitial(HashMap::new);

TtlExecutors.getTtlExecutorService(
            ExecutorServiceMgr.getExecutorService("esThreadPool",
                    ExecutorServiceMgr.CALLER_RUNS_HANDLER));

子线程不是会对父线程的HashMap做一份快照拷贝吗,那么即使子线程有修改map也不会影响父线程访问才对

@luocunhao luocunhao changed the title TransmittableThreadLocal是用HashMap造成ConcurrentModificationException TransmittableThreadLocal使用HashMap造成ConcurrentModificationException Jul 24, 2024
@oldratlee
Copy link
Member

oldratlee commented Jul 24, 2024

@luocunhao

可以看看使用withInitialAndCopier(Supplier supplier, TtlCopier copierForChildValueAndCopy)方法:

InheritableThreadLocal<Map<String, String>> logTagsLocal =
  TransmittableThreadLocal.withInitialAndCopier(HashMap::newHashMap::new);

PS:具体合适的解决方法与你需求相关。

更多说明参见已有issue:

@oldratlee oldratlee changed the title TransmittableThreadLocal使用HashMap造成ConcurrentModificationException 使用TransmittableThreadLocal<HashMap>出现ConcurrentModificationException Jul 24, 2024
@oldratlee oldratlee added the ❓question Further information is requested label Jul 24, 2024
@oldratlee oldratlee self-assigned this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants