Skip to content

Commit f9b11bc

Browse files
committed
AbstractSingletonService: initialize thread-safely
Further, do not add objects to the object index twice; only do it using the lazy hook rather than explicitly in addition.
1 parent 32d57c0 commit f9b11bc

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/main/java/org/scijava/plugin/AbstractSingletonService.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public abstract class AbstractSingletonService<PT extends SingletonPlugin>
6565

6666
@Override
6767
public List<PT> getInstances() {
68-
if (instances == null) {
69-
createInstances();
70-
}
68+
if (instances == null) initInstances();
7169
return instances;
7270
}
7371

@@ -93,18 +91,15 @@ public ArrayList<Object> get() {
9391

9492
// -- Helper methods --
9593

96-
private void createInstances() {
94+
private synchronized void initInstances() {
95+
if (instances != null) return;
96+
9797
instances =
9898
Collections.unmodifiableList(filterInstances(getPluginService()
9999
.createInstancesOfType(getPluginType())));
100100

101101
log.info("Found " + instances.size() + " " +
102102
getPluginType().getSimpleName() + " plugins.");
103-
104-
// register singleton instances with the object service
105-
for (final PT instance : instances) {
106-
objectService.addObject(instance);
107-
}
108103
}
109104

110105
/**

0 commit comments

Comments
 (0)