1 Reply Latest reply on Nov 3, 2010 11:18 AM by Will Piasecki

    Multiple instances of a Seam component

    Priya Srihari Newbie

      In my Seam - JPA(Hibernate) project, I have a Quartz scheduler that executes a database query based on a cron trigger and to perform additional processing on each record from the query , I use a ThreadPoolExecutor which assigns a thread per record.  In doing so, I would expect that each thread operates on  different instances of a Seam component. Instead its the same instance that is used each time and this results in a lot of hibernate-entity manager specific exceptions - Session is closed, EntityManager is closed, and a horde of other hibernate-specific exceptions.
      Also in this case, I cannot use @Roles for the component in question since the number of instances required is dynamic as the number of threads simultaneously executing active tasks.


      Can you suggest how i can get multiple instances of a component in Seam dynamically.


      Thanks in advance.
      Priya

        • 1. Re: Multiple instances of a Seam component
          Will Piasecki Newbie

          Hello, we had this issue recently and we solved it this way:


          @Name("dynamicComponent")
          class DynamicComponent implements Runnable {
            public void run() {
              // do things...
            }
          }




          @Name("dynamicController")
          class DynamicController {
            void doStuff() {
              for (int i = 0 ; i < 5; i++) {
                new Thread(Component.forName("dynamicComponent").newInstance()).start();
              }
            }
          }



          We printed the references of the objects and they all are different.