*
The moose likes Servlets and the fly likes Thread issues sorrounding using javabeans and helper classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Thread issues sorrounding using javabeans and helper classes" Watch "Thread issues sorrounding using javabeans and helper classes" New topic
Author

Thread issues sorrounding using javabeans and helper classes

Simon Harvey
Ranch Hand

Joined: Jan 26, 2003
Posts: 79
Hi,
I am hoping that someone could offer some general advice on thread safety when using helper classes and helper java beans.
In particular I am worried about a javabean that I have made that handles connection pooling and executing queries.
I decalre the datasource at the top of the class and then use it in a couple of methods to execute a given statement.
At its simplest, my question is, if this class is used by lots of jsp pages to get data, is it thread safe?
The other thing is, is there someway to make only one helper object and share it amongst various requesting pages? At the moment I think that each page makes a new helper javabean in order to execut its statement. Given that I want to share connections amongst pages, should I somehow be making sure that each page that is handling a request is going through only one instance of the helper class? How should I do this?
Thanks everyone
Kindest Regards
Simon
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

You can share the bean by declaring it in application scope. The bean will be stored in the servlet context and shared by all pages in the app.
And under these conditions it is very important to make the bean thread-safe since multiple pages can access it simultaneously.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Simon Harvey
Ranch Hand

Joined: Jan 26, 2003
Posts: 79
Thanks
Simon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread issues sorrounding using javabeans and helper classes