Commit a5261eb
authored
Synchronization of getInstance might fail?
Hey everyone,
I found this getInstance method generating a static singleton. I think the second `result = instance` should be moved into the synchronized block. Otherwise, this might result in multiple instances.
One question, is it necessary to use a local variable here? (I mean it does not hurt either)
This could also be changed to:
```java
public static IChemObjectBuilder getInstance() {
if (instance == null) {
synchronized (LOCK) {
if (instance == null) {
instance = new SilentChemObjectBuilder();
}
}
}
return instance;
}
```1 parent 84894c8 commit a5261eb
File tree
1 file changed
+1
-1
lines changed- base/silent/src/main/java/org/openscience/cdk/silent
1 file changed
+1
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
224 | 223 | | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
0 commit comments