7 Replies Latest reply on Jan 4, 2010 3:20 AM by Nikolay Elenkov

    back group threads without user interactions

    tiger zhao Newbie

      I have some back group threads to run when application starts up. These threads are moving from old code and are doing a lot of works without user interactions. So, I think there is no seam event here. How can I use seam context, especially entity manager?
        Thanks in advance!


      Below is my sample code.


      public class MyThread extends Thread {
           @Override
           public void run() {
           //TODO:
           //there is not seam context here. how can I use entity manager here ? 
           
           for(;;){
                //do routine job .....
           }
           
           }
      }
      
      
      @Scope(ScopeType.APPLICATION)
      @Name("backgroupPool")
      @Startup
      public class BackgroupPool extends Thread {
      
      /*
           EntityManagerFactory entityManagerFactory;
           public EntityManagerFactory getEntityManagerFactory() {
                org.jboss.seam.contexts.Context applicationContext = (org.jboss.seam.contexts.Context) Contexts
                          .getApplicationContext();
                if (applicationContext != null) {
                     org.jboss.seam.persistence.EntityManagerFactory entityManagerFactory3 = (org.jboss.seam.persistence.EntityManagerFactory) applicationContext
                               .get("dbTestEntityManagerFactory");
                     if (entityManagerFactory3 != null) {
      
                          entityManagerFactory = entityManagerFactory3
                                    .getEntityManagerFactory();
      
                     }
                }
      
           }
      */     
           @Override
           public void run() {
      
                for (int i = 0; i < 10; i++) {
                     MyThread thread = new MyThread();
                     thread.start();
                }
      
           }
           
           @Observer("org.jboss.seam.postInitialization")
           public void init() {
                //getEntityManagerFactory
                this.startup();
      
      
           }