aspose file tools
The moose likes Threads and Synchronization and the fly likes database connectivity - multithread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "database connectivity - multithread" Watch "database connectivity - multithread" New topic
Author

database connectivity - multithread

Ann Kanu
Ranch Hand

Joined: Feb 01, 2004
Posts: 30
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

Joined: Jan 15, 2004
Posts: 23
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

Joined: Nov 15, 2002
Posts: 70
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database connectivity - multithread
 
Similar Threads
How to prompt if there is no match in database using servlet?
jspInit() method
Keeping code out of the Servlet
querying html/servlet
threads-database connection-servlet