pepness commented on code in PR #6542:
URL: https://github.com/apache/netbeans/pull/6542#discussion_r1355932410
##########
enterprise/glassfish.tooling/src/org/netbeans/modules/glassfish/tooling/server/config/ConfigBuilderProvider.java:
##########
@@ -193,16 +209,13 @@ public static ConfigBuilder getBuilder(final
GlassFishServer server) {
"GlassFish server entity shall not be null");
}
ConfigBuilder builder;
- synchronized (builders) {
- builder = builders.get(server);
- if (builder != null) {
- return builder;
- }
- String serverHome = server.getServerHome();
- builder = new ConfigBuilder(config, serverHome, serverHome,
serverHome);
- builders.put(server, builder);
+ builder = builders.computeIfPresent(server, (key, value) -> value);
+ if (builder != null) {
+ return builder;
}
- return builder;
+ String serverHome = server.getServerHome();
+ return builders.computeIfAbsent(server, key ->
+ new ConfigBuilder(config, serverHome, serverHome, serverHome));
Review Comment:
Both versions will compute the same results. But the old version does not
allow concurrent modifications to the map, the new version will allow
concurrent modifications to the map.
Old version:
```java
synchronized (entireMap) {
// checked if `server` key was in the map, if it was, it returned it's
value.
// if it wasn't in the map, it created a new ConfigBuilder, registered
it in the map and returned it
}
```
New version restrict modifications at a node level e.g. `Node[K1,V1]` until
it finish, but allows concurrent modifications to every other node e.g.
`Node[K2,V2]`:
```java
synchronized (Node[K1,V1]) {
// Thread 1
// No one can modify this node until I finish
}
synchronized (Node[K2,V2]) {
// Thread 2
// Modifying this node at the same time that Thread 1 is working on
Node[K1,V1]
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists