2 Replies Latest reply on Jun 10, 2007 11:10 AM by Suat Kaya

    Issuing Commands to a Running Process

    Suat Kaya Newbie

      Hi,

      For some reason, my stateless session bean starts a long running "process" (not in OS terms) like this code:

      private @Resource SessionContext sctx;
      .....
      sctx.getTimerService().createTimer(1, obj);
      


      The long running process is in timer code. And it creates a Queue object and gives it a JNDI name like this:

      @Timeout
       public void timeoutHandler(javax.ejb.Timer timer)
       {
       InitialContext inictx = new InitialContext();
       this.commandQueue = new ConcurrentLinkedQueue<SomeMsg>();
       inictx.bind("CmdQueue", this.commandQueue);
       }
      


      And this created queue is used to accept commands from other session beans, like this:

      SomeMsg msg = this.commandQueue.poll();
      


      And then acts accordingly. Other session beans can send a message to this process like the following:

      InitialContext ctx = new InitialContext();
      Queue<SomeMsg> queue = (Queue<SomeMsg>) ctx.lookup("CmdQueue");
      queue.add(msg);
      


      And the process unbinds the name before finishing.

      Are there any pitfalls in this approach?