Hi, There is generally two ways that I have done this in the past. The first one is to bind the Session/Context to a thread local. And then have a method like
Session s = Session.getSession() that got the session associated with current thread. This works great when each request is handled by a single thread and you will find that most "enterprise" object frameworks basically do that. You can throw an IllegalStateException if it has not been set. If you have multiple threads per request then you have a problem. You have to start worrying about what to do when cross thread boundaries. ie Do you clone the context or do both threads refer to the same context. And if the request ends and a thread is still going what happens to that threads context? Anyways I have repeatedly tried to do multi-thread requests and failed every time so I wouldn't recomend that approach ;) The other approach is to pass around the session object through all the components. This is what many Servlet frameworks do (ie the pass around request/response/servletContext to all components that need it). So most of your methods will end up looking like void doSomething( Session session, int param1, int param2 ); This is a little safer wrt to multiple threads but you still have to deal with the issue - what happens when request ends? Anyways my recomendation would be to bind to thread locals and have each request in separate thread - we are currently using the second approach in one clients project and regret it hugely ;) -- Cheers, Peter Donald *-------------------------------------------------* | An eye for eye only ends up making the whole | | world blind. - Gandhi | *-------------------------------------------------* --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
