Hi. I have a question about how a client application knows which instance of a stateful bean belongs to it. Let's assume we have a bean called ShoppingCart. When a client connects to the application, it gets a shopping cart it can add things to. There are two cases I have questions about.
Case 1: Assume we have a thick java client (i.e. written in Swing for example). If multiple methods in that client need to lookup the shopping cart bean (and they don't pass the bean between them), will multiple methods know to lookup the same version of the bean? Or do I need to pass around some session identifier?
Case 2: Assume we have a browser client. And in my web application, there is a Java servlet that serves as a facade for looking up the EJB. In this case, do I need to pass the browser session ID to get the correct bean? Or will the servlet know that it was the same browser making a request and get the correct bean?
The client will interact with a particular bean when using the bean's reference or Handle. You only need to pass the reference or Handle to the methods of the client(s).
If the methods are all invoked from the same client instance, then just reuse the same reference for all method calls. If you have different clients, perhaps making calls at different times, then serialize the Handle after the first client has finished with the bean and deserialize the Handle for the next client.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Don't play dumb with me! But you can try this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth