0 Replies Latest reply on Jul 12, 2013 11:56 AM by Juan Ignacio Garzon

    Best way for creating a background always running thread

    Juan Ignacio Garzon Newbie

      Hi, I have to implement a process that always keeps running in background, forever. I want to know if the way I'm implementing it is the most "seamish" way to do it. The process will have to access an EntityManager:

       

      @Name("messageReceiver")
      @Scope(ScopeType.APPLICATION)
      @Startup
      public class MessageReceiver implements Runnable {
          private Thread thread;
      
          public MessageReceiver() {
              thread = new Thread(this);
              thread.run();
          }
      
          @Override
          public void run() {
              // do my stuff forever
          }
      }
      

       

      It is not important for this question I think, but if it matters, I want to implement a JMS receiver (I dont like te way Seam JMS module is implemented because it uses polling, and I want an always living connection for better time responses).

       

      Thanks a lot!!