• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB's and Timer Thread

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic