-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Update ExtensionRepository.java #569
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ public Map<ExtensionCoordinate, ExtensionPointI> getExtensionRepo() { | |
| return extensionRepo; | ||
| } | ||
|
|
||
| private Map<ExtensionCoordinate, ExtensionPointI> extensionRepo = new HashMap<>(); | ||
| private Map<ExtensionCoordinate, ExtensionPointI> extensionRepo = new ConcurrentHashMap<>(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Minor:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Suggestion:
|
||
|
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 Major: 仅将
HashMap替换为ConcurrentHashMap并不能保证线程安全。ExtensionRegister中的写入路径是 check-then-act 模式:先put再检查preVal != null来检测重复,但ConcurrentHashMap.put()本身不是原子的 check-then-act 操作——两个线程可能同时put成功并都看到preVal == null,导致重复注册被漏检。建议方案:
ConcurrentHashMap+putIfAbsent替代put+ 检查返回值,在ExtensionRegister中改为:ExtensionPointI preVal = extensionRepository.getExtensionRepo().putIfAbsent(extensionCoordinate, extensionObject);@PostConstruct阶段单线程执行,运行时只读,则HashMap已足够,加volatile或改ConcurrentHashMap反而增加不必要的复杂度。请确认实际并发场景。