• Post Reply Bookmark Topic Watch Topic
  • New Topic

database connectivity - multithread

 
Ann Kanu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application running on weblogic, I am using the MVC pattern with jsps for creating views, a controller servlet and java classes for business logic. I have a seperate class for establishing database connection / checking out database connection from the connection pool. In the service() method of my controller servlet, I use one of the classes, performing business logic, which in turn uses the Database connection class for performing select/updates on the database tables. This is a portion of my code from the service() method.
if ( functionCode.equalsIgnoreCase("EDIT")) {
School school = new school(req,loginUserId,functionCode);
school.setLoginUserId(loginUserId);
school.saveChanges();
String function = "Edit";
showSuccess(function,req,res);
}
In this scenario, should I be concerned about multithreading issues regarding database connectivity in the class School? If so, what portions of my code would I need to synchronize.
Thanks,
Ann
 
Siyaa Hoffman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ann,
This is what I think...
Looking at your code, I could see that the object School is being created in the local "service" call. Since all the local variables are in the thread stack and are not shared across the threads, as far as the variable is concerned, it is safe.
It could happen that muliple requests coming in at one point of time, would create multiple School objects which would call multiple "update"s on the database at the same time.
Now, this is in the hands of your databse as to how concurrent update requests are handled by it.
If the database is okay with this(for e.g. oracle etc.), then I do not think there is any need for synchronization.
 
V Chauhan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well.. One part of your code where you need to incorporate synchronization is your connection pool. There will be a single pool for all clients. So the methods for getting a connection from the pool, returning the connection back to the pool etc.. should be synchronized.
Correct me if i'm wrong..
Basu.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!