[picocontainer-scm] [5680] java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java: An attempt and fixing PICO-367

rimovm-yCVjj/[email protected]
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <[email protected]>
Revision 5680
Author rimovm
Date 2010-04-16 15:58:55 -0500 (Fri, 16 Apr 2010)

Log Message

An attempt and fixing PICO-367

Modified Paths

- java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java

Diff

Modified: java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java (5679 => 5680)

--- java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java 2010-04-15 15:10:06 UTC (rev 5679)
+++ java/2.x/trunk/pico/container/src/java/org/picocontainer/DefaultPicoContainer.java 2010-04-16 20:58:55 UTC (rev 5680)
@@ -562,7 +562,7 @@
}
}

- private void addOrderedComponentAdapter(final ComponentAdapter<?> componentAdapter) {
+ private synchronized void addOrderedComponentAdapter(final ComponentAdapter<?> componentAdapter) {
if (!getOrderedComponentAdapters().contains(componentAdapter)) {
getOrderedComponentAdapters().add(componentAdapter);
}
@@ -578,22 +578,25 @@
}

Map<ComponentAdapter<T>, T> adapterToInstanceMap = new HashMap<ComponentAdapter<T>, T>();
- for (ComponentAdapter<?> componentAdapter : getModifiableComponentAdapterList()) {
- if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) {
- ComponentAdapter<T> typedComponentAdapter = typeComponentAdapter(componentAdapter);
- T componentInstance = getLocalInstance(typedComponentAdapter);
-
- adapterToInstanceMap.put(typedComponentAdapter, componentInstance);
- }
- }
List<T> result = new ArrayList<T>();
- for (ComponentAdapter<?> componentAdapter : getOrderedComponentAdapters()) {
- final T componentInstance = adapterToInstanceMap.get(componentAdapter);
- if (componentInstance != null) {
- // may be null in the case of the "implicit" addAdapter
- // representing "this".
- result.add(componentInstance);
+ synchronized(this) {
+ for (ComponentAdapter<?> componentAdapter : getModifiableComponentAdapterList()) {
+ if (componentType.isAssignableFrom(componentAdapter.getComponentImplementation())) {
+ ComponentAdapter<T> typedComponentAdapter = typeComponentAdapter(componentAdapter);
+ T componentInstance = getLocalInstance(typedComponentAdapter);
+
+ adapterToInstanceMap.put(typedComponentAdapter, componentInstance);
+ }
}
+
+ for (ComponentAdapter<?> componentAdapter : getOrderedComponentAdapters()) {
+ final T componentInstance = adapterToInstanceMap.get(componentAdapter);
+ if (componentInstance != null) {
+ // may be null in the case of the "implicit" addAdapter
+ // representing "this".
+ result.add(componentInstance);
+ }
+ }
}
return result;
}
@@ -739,7 +742,7 @@
* @see #addChildContainer(PicoContainer)
* @see #removeChildContainer(PicoContainer)
*/
- public void start() {
+ public synchronized void start() {

lifecycleState.starting();

@@ -768,7 +771,7 @@
* @see #addChildContainer(PicoContainer)
* @see #removeChildContainer(PicoContainer)
*/
- public void stop() {
+ public synchronized void stop() {

lifecycleState.stopping();

@@ -818,7 +821,7 @@
* @see #addChildContainer(PicoContainer)
* @see #removeChildContainer(PicoContainer)
*/
- public void dispose() {
+ public synchronized void dispose() {
if (lifecycleState.isStarted()) {
stop();
}

----------

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.