Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about thread safe implementation

 
Thierry Collogne
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
else
dh = new DatabaseHandler();

Response response = dh.GetPlayers();

Vector players = response.getPlayers();

request.setAttribute("players",players);

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?

Thierry
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic