File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Question about thread safe implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Question about thread safe implementation" Watch "Question about thread safe implementation" New topic

Question about thread safe implementation

Thierry Collogne

Joined: Oct 19, 2005
Posts: 16
Hi all,

I am developping a struts application with database communication.

For the database functionality, I use a java class "DatabaseHandler" wich is stored in the session. I
n this class I implement all my database functionality. All my results of methods in the DatabaseHandler are stored in a javabean called Reponse.
The object stored is a Vector with objects of Player.

It goes like this.

public class GetPlayersAction extends Action {
public ActionForward execute(...) {

HttpSession session = request.getSession();

DatabaseHandler dh = null;

if(session.getAttribute("databaseHandler") != null)
dh = session.getAttribute("databaseHandler");
dh = new DatabaseHandler();

Response response = dh.GetPlayers();

Vector players = response.getPlayers();


return mapping.findForward("players");



Then on the JSP page I can get the players vector from the request and display its content on the page.

Can this pose thread safe issues or not?

Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I don't see any glaring threading issues here, but a lot would depend on your DatabaseHandler class. Did you roll your own database connection code, or are you using some type of connection pooling? Since you are storing your DatabaseHandler on the session, each user will have their own instance. If each instance of your DatabaseHandler class tries to maintain its own database connection then I could see scalability issues.

BTW, do you ever call session.setAttribute to set the "databaseHandler" attribute?

- Brent
[ March 03, 2006: Message edited by: Brent Sterling ]
Thierry Collogne

Joined: Oct 19, 2005
Posts: 16
Thank you for your response

I call the session.setAttribute(). I just forgot to mention it.

For database connection I use a java.sql.datasource which is declared in my tomcat server.xml. I believe that this gives me connection pooling, or am I wrong?
I agree. Here's the link:
subject: Question about thread safe implementation
jQuery in Action, 3rd edition