PicoContainer
  1. PicoContainer
  2. PICO-69

Synchronization Issues with TransientComponentAdapter

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Critical 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 :
      0

      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()

      { SomethingFast fast = (SomethingFast) pico.getComponentInstance("key"); }

      };

      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

      { // think of something that queries remote objects // or anything that _might_ be slow Thread.sleep(10000); }

      }

      public static class SomethingFast
      {
      private final VerySlow slow;
      public SomethingFast(VerySlow slow)

      { this.slow = 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

        Hide
        Thomas Heller added a comment -

        refactoring made this problem move to InstantiatingComponentAdapter.

        Show
        Thomas Heller added a comment - refactoring made this problem move to InstantiatingComponentAdapter.
        Show
        Aslak Hellesøy added a comment - Fixed a few days ago. Just forgot to close the issue. See http://cvs.codehaus.org/viewcvs.cgi/pico/src/test/org/picocontainer/extras/SynchronizedComponentAdapterTestCase.java?rev=1.1&root=picocontainer&view=auto
        Aslak Hellesøy made changes -
        Field Original Value New Value
        Resolution Fixed [ 1 ]
        Fix Version/s 1.0 [ 10145 ]
        Assignee Aslak Hellesoy [ rinkrank ]
        Status Open [ 1 ] Closed [ 6 ]
        Aslak Hellesøy made changes -
        Resolution Fixed [ 1 ]
        Status Closed [ 6 ] Reopened [ 4 ]
        Aslak Hellesøy made changes -
        Fix Version/s 1.0-beta-4 [ 10412 ]
        Fix Version/s 1.0 [ 10145 ]
        Resolution Fixed [ 1 ]
        Status Reopened [ 4 ] Closed [ 6 ]

          People

          • Assignee:
            Aslak Hellesøy
            Reporter:
            Thomas Heller
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: