| Author |
EJB's and Timer Thread
|
Joel Carklin
Greenhorn
Joined: Jun 15, 2001
Posts: 28
|
|
Hi ejb-guru's I have 2 related questions I hope someone can advise me on (I'm new to EJB's), relating to the java.util.Timer class and EJB's <Context> I am working on a basic shopping cart system, using a stateful-session bean to represent the customers shopping process. The customer reserves items (ie puts them in his cart while continuing to shop), then, after a specified time, if he has not checked out those items(ie moved to payment stage) they will automatically be unreserved until such time as he is ready to pay (at which time the system will attempt to rereserve them). I wanted to use the util.Timer class and util.TimerTask to schedule and implement this unreservation process. </context> <Questions> Firstly, the Timer class works by creating a seperate thread to run in. I know(although I don't fully understand why) that it is prohibited to create threads in a J2EE container since threads are managed by the container and shouldn't be messed with. How will using the Timer class affect / be affected by this? Is there a better way? Second, if I create the Timer object in the stateful session bean it would mean that for every customer there will be a seperate thread running which is obviously not ideal. Ideally, I want to be able to create one Timer thread that all the EJB's can share. Is this possible, any clues on how I might implement such a scenario? Could I use a servlet to do it? We want to avoid writing a seperate service that's external to the J2EE container/server. </Questions> Any comments / ideas appreciated Joel
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 12513
|
|
|
I think you'll find it simpler to store the cart in a Jsp/Servlet session. The session can be made to expire much more easily - you don't need to give it a timer task, as that's something its container can handle.
|
One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
|
 |
 |
|
|
subject: EJB's and Timer Thread
|
|
|