4 Replies Latest reply on Nov 3, 2002 6:04 PM by joelvogt

    Thread in message bean

    magicman

      Hope someone can help me with this, I have no idea what I'm doing. Anyway I'm working on jboss 2.4.3, win2k, jdk1.3.1, tomcat 4. I've created a Queue message bean and in the onMessage method I call the wait3minute() method which wait 3 minutes and then does an operation. here is the code

      public void onMessage(Message message) {
        doStuff.......
        wait3min(message);
      }

      public static Object sync_obj;

      public static void wait3min(BidAsk bidAsk) {
        sync_obj = bidAsk;
        Thread t = new Thread(new Runnable() {
         public void run() {
          System.out.println("Notifier-Thread: waiting for 4000ms");
          try {
          Thread.sleep(1000*60*4);
         } catch (InterruptedException e) {
        }
        System.out.println("Notifier-Thread: again up to work");
        synchronized (sync_obj) {
         System.out.println("Notifier-Thread: execute to notify");
         sync_obj.notifyAll();
        }
         System.out.println("Notifier-Thread: it's over now");
        }
        });
         synchronized (sync_obj) {
          System.out.println("main: start thread and wait for notify");
          t.start();
          try {
           sync_obj.wait();
          } catch (InterruptedException e) {
         }
        }
         System.out.println("main: notify received --> and bye ...");
        }

      If anyone know what to do, please let me know

        • 1. Re: Thread in message bean
          parsonskerins

          The EJB specification specifically forbid the creation of threads within an EJB - thread control is the domain of the EJB container. Some application servers will allow you, perhaps, to start your own threads, but you will loose portability of the EJB.

          • 2. Re: Thread in message bean
            ahjulsta

            What will solve the problem, however, is using a Timer MBean or a Scheduler. Examples of this are can be found in the configuration files, (jboss-service.xml). It is also covered in the free doco.

            • 3. Re: Thread in message bean

              easy! you can send an objectmessage to an MDB with an object of the type - Runnable & Serializable. MDB do the work in another thread and if you send many such message, MDB can concurrently do the job. With clustered environment, very high performance could be acheived. But I don't know how to control the thread number serving the MDB. Any solutions please let me know (simontm_cn@sina.com)

              • 4. Re: Thread in message bean
                joelvogt

                settings are in standardjboss.xml