| Author |
Synchronization Problem whil accessing JDBC Code
|
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
Hi,
In my project i am having DBUtils package. This package consists of classes with all static methods that interact with database. My project is web based.will i get concurrency problems when accessing static methods of my DBUtils package.
Can any one tell me where can i get concurrency problem...
Thanks & Regards,
Vipul Kumar Bondugula.
|
Thanks
Vipul Kumar
|
 |
Abhishek Ralhan
Ranch Hand
Joined: Aug 01, 2010
Posts: 40
|
|
Never heard in a web application, static methods would access database.
Would like to know the responses though.
Anyone please respond..
|
-Abhishek
I came to this world on a Learner's License
|
 |
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
Hi Abhishek,
Sorry ,yesterday i posted wrongly..DBUtils is a class not a package.
I am posting a sample code ..static method that interacts with database
This is the sample code.I am having DAO layer.In DAO I won't write the JDBC code.I am writing in DBUtils class.
In DAO's iam calling the static methods of DBUtils class
So when 2 users send request then 2 threads will create.while accessing this static method any concurrent issues arise or not.
If arise ,what is the solution.
Please anyone tell the solution..
|
 |
Madhan Sundararajan Devaki
Ranch Hand
Joined: Mar 18, 2011
Posts: 312
|
|
|
Concurrency problems will arise. Please synchronize all the static methods in the DBUtils class.
|
S.D. MADHAN
Not many get the right opportunity !
|
 |
Sudheer Bhat
Ranch Hand
Joined: Feb 22, 2011
Posts: 75
|
|
|
I don't think you need to synchronize all the static methods. Especially if your static methods do not modify any shared resources. Databases have their own implementation of concurrency control. You need to visit each and every method and evaluate whether or not you need to synchronize. These decisions has to be taken on a case by case basis.
|
 |
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
Thanks Sudheer Bhat,..
can you guide me how to know the different cases. Is there any document on how & when to synchronize...
Thanks In Advance
|
 |
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
Hi Every one,
Please anyone guide me in when to use synchronization.Please provide any document.
Thanks In Advance
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
|
Why is everything static? That's where the problem lies. Fix the problem, don't band-aid it with synchronization.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
Thanks For Your Reply Bear,
In my project iam almost everywhere using DBUtils class which consists of database access static methods.Suppose ,If i go on creating the objects for DBUtils class then a lot of objects will be created.Instead of creating objects i made my methods static. I thought that adds support to performance....
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
Creating objects are almost never a performance problem. The time to create an object is negligible compared to a single database access.
What does this method do?
con = ConnectionManager.getInstance().getConnection();
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
Thanks Jeanne,
ConnectionManager is a singleton class.ConnectionManager.getInstance() returns the instance and ConnectionManager.getInstance.getConnection method returns connection object.
In the getConnection method i wrote the database connection code.
I used the DBUtils class almost everywhere in the project. Now if make every method in DBUtils as instance method, my team had to work a lot.In the whole project they need to modify..So ,tell me that i can modify in only DBUtils class.
Thanking & Regards,
Vipul Reddy Bondugula.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
vipul bondugula wrote: ConnectionManager is a singleton class.ConnectionManager.getInstance() returns the instance and ConnectionManager.getInstance.getConnection method returns connection object.
In the getConnection method i wrote the database connection code.
I see. And where do you close the connection?
|
 |
vipul bondugula
Ranch Hand
Joined: Oct 14, 2010
Posts: 218
|
|
In DAO layer I call this method and get the connection object.Then in the DAO layer i'll close the connection.
|
 |
 |
|
|
subject: Synchronization Problem whil accessing JDBC Code
|
|
|