Details
-
Type: Bug
-
Status: Closed
-
Priority: Critical
-
Resolution: Fixed
-
Affects Version/s: 1.0-beta-5
-
Fix Version/s: 1.0-beta-4
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Environment:.
-
Number of attachments :
Description
TransientComponentAdapter.getComponentInstance() should/must be synchronized.
Why:
package pico;
import junit.framework.TestCase;
import org.picocontainer.defaults.DefaultPicoContainer;
import org.picocontainer.defaults.TransientComponentAdapter;
public class TimingProblemTestCase extends TestCase
{
public void testTimingProblems() throws Exception
{
final DefaultPicoContainer pico = new DefaultPicoContainer();
pico.registerComponentImplementation(VerySlow.class);
pico.registerComponent(new TransientComponentAdapter("key", SomethingFast.class));
Runnable test = new Runnable() {
public void run()
};
Thread t1 = new Thread(test);
Thread t2 = new Thread(test);
t1.start();
t2.start();
Thread.currentThread().join();
}
public static class VerySlow
{
public VerySlow() throws InterruptedException
}
public static class SomethingFast
{
private final VerySlow slow;
public SomethingFast(VerySlow slow)
}
}
the resulting exception:
org.picocontainer.defaults.CyclicDependencyException: Cyclic dependency: pico.TimingProblemTestCase$SomethingFast(pico.TimingProblemTestCase$VerySlow)
at org.picocontainer.defaults.TransientComponentAdapter.instantiateComponent(TransientComponentAdapter.java:160)
at org.picocontainer.defaults.TransientComponentAdapter.getComponentInstance(TransientComponentAdapter.java:153)
at org.picocontainer.defaults.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:165)
at pico.TimingProblemTestCase$1.run(TimingProblemTestCase.java:27)
at java.lang.Thread.run(Thread.java:534)
One might argue that the instantiation process is required to be fast but nonetheless we live in a multithreaded world and even if its a very fast constructor the problem remains.
Activity
Field | Original Value | New Value |
---|---|---|
Resolution | Fixed [ 1 ] | |
Fix Version/s | 1.0 [ 10145 ] | |
Assignee | Aslak Hellesoy [ rinkrank ] | |
Status | Open [ 1 ] | Closed [ 6 ] |
Resolution | Fixed [ 1 ] | |
Status | Closed [ 6 ] | Reopened [ 4 ] |
Fix Version/s | 1.0-beta-4 [ 10412 ] | |
Fix Version/s | 1.0 [ 10145 ] | |
Resolution | Fixed [ 1 ] | |
Status | Reopened [ 4 ] | Closed [ 6 ] |
refactoring made this problem move to InstantiatingComponentAdapter.