Joe, Triggering an event to occur in EJB 2.0 is normally done using JMS. Then a Message Driven Bean is used to pick up the message and do the necessary processing. The source of the message could be an external client application (which IS allowed to start any number of threads it wants). The external client application could be configured to start/stop with the server (Weblogic startup/shutdown classes, or similar mechanism in other servers).
With a statefull session bean, you have a problem. Since only 1 client is allowed to use session beans (they are not to be shared between clients), how will the event triggered by an external program (another client) reach the session? If you allow that to happen, you now have two clients using the same session bean (some containers might allow that, others will probably throw an exception). Also, I do not think that statefull session beans will survive a server crash. This if your server goes down, all the sessions might be lost. I would use Entity beans to represent your basket, and switch to using stateless session beans to wrap a "facade" around your Entities. This way, you can fire a timer from your external client every 5 minutes. A message driven bean (MDB) can pick up the event from a queue and SELECT (i) FROM basketItems WHERE basketItems.timeReserved < "now - 5 minutes". The question, I have, is how do you calculate when the "specified time" has occurred? In other words, a customer can shop around an put first item in the container (t1). Then 5 minutes later the customer adds another item (t2), 10 minutes later (t3), 5 more minutes (t4). As you can see the shopping experience has lasted 20 minutes. Do you start a single timer for the customer with the first item placed in to the basket? Does each item has a specified timeout? So there is a "timer" for the first item, second item and third item? So it's quite possible then, that by the time customer places the last item in the basket, the first item might have been unreserved and is no longer available? (At this point, customer could get upset, and cancel the whole order). What about your reservation process? Can you describe a little on how you are doing that? Is there a "reserved" field in the ProductEJB? -AP_ -----Original Message----- From: A mailing list for Enterprise JavaBeans development [mailto:[EMAIL PROTECTED]]On Behalf Of Joel Carklin Sent: Tuesday, October 16, 2001 12:59 AM To: [EMAIL PROTECTED] Subject: EJB's and Timer Thread 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 buy creating a seperate thread to run in. I have been told (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? </Questions> Any comments / ideas appreciated Joel ========================= To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
