interrupt thread in session bean


EJB programming & troubleshooting: interrupt thread in session bean

  1. interrupt thread in session bean (4 messages)

    if I use Thread.sleep(5000) in a method of sessioni bean object, how can I interrupt this sleep?
  2. You should not use Tread.sleep() or any methods related to thread management in EJB. Simply DO NOT. Because you cannot interrupt this slumber. No way.

    If you need to perform some activity at regular interval, then use other approaches:
    1. If your server vendor supports some kind of Timer/Scheduler service, then use this to post a message to JMS
    2. If your server vendor adopts JMX, write an MBean that uses JMX timer to post message to JMS
    3. Write a stand-alone program to post message to JMS

    Then handle message in MDB subscriber (that will work in J2EE managed env. and call your "always awaken" SLSB, for example).

    Or wait till J2EE 1.4 with Timer MDB :-)

  3. the following is the behavior of my program:

    do something

    sleep 5 minutes

    if interrupted then do ...
    else do ...

    sleep 2 mintues

    if interrupted then do ...
    else do ...

    and so on

    How can i implement the above hehavior by ejb if i don't use a stand-alone program?
    Maybe the ejb is not suitable for this kind of task.
  4. If I understand you correct, your program should perform ceratin actions on long-running tasks interruption, rather then simple schedule this tasks, right?

    If so, then EJB does not seem to be a suitable technology here. Probably, it's more simple to implement your program as "regular" multithreaded Java program.

  5. Can my ejb call some object which manages threads?