We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
https://github.com/Viscent/javamtia/blob/06faaaa9610a8b9af2ee0eec551a0365154ef8fa/JavaMultiThreadInAction/src/io/github/viscent/mtia/ch5/ThreadTerminationRegistry.java 有add方法 public synchronized void register(Handler handler) { handlers.add(handler); } 但并没有 public synchronized void remove(Handler handler) { handlers.remove(handler); } 如果在生产环境中,handlers会越来越大,是否会内存溢出?
private final Set handlers = new HashSet();
能否改为
private final Set handlers = new ConcurrentHashSet();
register 和 remove 方法去掉 synchronized 关键字是否也能达到线程安全,并且效率更高。
比如以下写法: private final Set handlers = Collections.newSetFromMap(new ConcurrentHashMap<Handler,Boolean>());
public void register(Handler handler) { handlers.add(handler); } public void remove(Handler handler) { handlers.remove(handler); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://github.com/Viscent/javamtia/blob/06faaaa9610a8b9af2ee0eec551a0365154ef8fa/JavaMultiThreadInAction/src/io/github/viscent/mtia/ch5/ThreadTerminationRegistry.java
有add方法
public synchronized void register(Handler handler) {
handlers.add(handler);
}
但并没有
public synchronized void remove(Handler handler) {
handlers.remove(handler);
}
如果在生产环境中,handlers会越来越大,是否会内存溢出?
private final Set handlers = new HashSet();
能否改为
private final Set handlers = new ConcurrentHashSet();
register 和 remove 方法去掉 synchronized 关键字是否也能达到线程安全,并且效率更高。
比如以下写法:
private final Set handlers = Collections.newSetFromMap(new ConcurrentHashMap<Handler,Boolean>());
The text was updated successfully, but these errors were encountered: