Link to home
Start Free TrialLog in
Avatar of manojvelliyatt
manojvelliyatt

asked on

Calling Tread.sleep() in session bean


Hi All,

i want to implement the retry logic inside one stateless session bean.
is it a good idea to call Thread.sleep() for making the current thread to wait before doing the retry?
is the Thread.sleep() will sleep the current execution thread?is there any side effect if i am make sleeping the thread which spaun by EJB container?
or any other way i can implement this?

All the inputs are welcome

regards
manoj velliyatt
Avatar of zzynx
zzynx
Flag of Belgium image

>> is the Thread.sleep() will sleep the current execution thread?
sleep() "causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds"
Avatar of manojvelliyatt
manojvelliyatt

ASKER

i am looking for usage inside the Stateless Session bean.
>> any other way i can implement this?
Using a Timer that triggers the retry functionality every x milliseconds

it is prohibited to deal with threads in session or entity bean, if you want to implement scheduled logic, then u need EJB Timer bean which is available if the J2EE App Server is J2EE 1.4 complaint and the EJB is version 2.1 complaint, otherwise their is components like Quartz (open source) that help u to do soo, refer to this link:

http://www.opensymphony.com/quartz/
>>  want to implement the retry logic inside one stateless session bean. is it a good idea to call Thread.sleep()
As petmagdy said you the EJB spec says that you should not interfer with the container threads directly (e.g by using sleep). (though the container will probably not notice that) .
EJB timer can trigger an SSB (one from the pool that is not currently in use) at specific time but I am not sure if this is what you are looking as you are expecting the synchrnous blocking call made by the client to come up with the response (after retry).
What is the operation you are taking from your SSB that you think will be available/successful after a short sleep?
I think it is OK for you to use sleep() simply and straightforward in your case.
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or to comment on the necessity of that sleep ;-)
i am making some http call from my stateless session bean to do some thing.Some times the server can be busy.So i want to give a option of retry the same call after some time.i don't want to give up the call in first attempt because this session bean is part of a pipeline.So before that so many things happened before i got the data for processing.it is for giving the flexibility for the component; most of the times this retry situation will not comes into picture.

i have gone through the spec.it is not talking about making a sleep() call on the working thread.

                            The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt
                            to start, stop, suspend, or resume a thread, or to change a thread’s priority or name. The enterprise
                            bean must not attempt to manage thread groups.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
r u using the Thread this way:

Thread.currentThread().sleep(number);
Any differnce between calling Thread.currentThread().sleep(number); and Thread.sleep(number);

Both will work on curent execution thred right?
well try hread.currentThread().sleep(number) maybe it is different not sure
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks