File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread issues sorrounding using javabeans and helper classes

 
Simon Harvey
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Simon Harvey
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Simon
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic