• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB's and Timer Thread

 
Joel Carklin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!