3131
3232package org .scijava .plugin ;
3333
34- import java .util .ArrayList ;
3534import java .util .Collections ;
3635import java .util .List ;
3736
@@ -58,15 +57,12 @@ public abstract class AbstractSingletonService<PT extends SingletonPlugin>
5857 // TODO: Listen for PluginsAddedEvent and PluginsRemovedEvent
5958 // and update the list of singletons accordingly.
6059
61- /** List of singleton plugin instances. */
62- private List <PT > instances ;
63-
6460 // -- SingletonService methods --
6561
6662 @ Override
6763 public List <PT > getInstances () {
68- if ( instances == null ) initInstances ( );
69- return instances ;
64+ final List < PT > plugins = objectService . getObjects ( getPluginType () );
65+ return Collections . unmodifiableList ( plugins ) ;
7066 }
7167
7268 @ Override
@@ -84,7 +80,7 @@ public void initialize() {
8480
8581 @ Override
8682 public List <PT > get () {
87- return new ArrayList < PT >( getInstances () );
83+ return createInstances ( );
8884 }
8985
9086 @ Override
@@ -97,15 +93,14 @@ public Class<?> getType() {
9793
9894 // -- Helper methods --
9995
100- private synchronized void initInstances () {
101- if (instances != null ) return ;
102-
103- instances =
104- Collections .unmodifiableList (filterInstances (getPluginService ()
105- .createInstancesOfType (getPluginType ())));
96+ private List <PT > createInstances () {
97+ final List <PT > instances =
98+ filterInstances (getPluginService ().createInstancesOfType (getPluginType ()));
10699
107100 log .info ("Found " + instances .size () + " " +
108101 getPluginType ().getSimpleName () + " plugins." );
102+
103+ return instances ;
109104 }
110105
111106 /**
0 commit comments