Forums Register Login

Synchronization Problem whil accessing JDBC Code

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Never heard in a web application, static methods would access database.
Would like to know the responses though.

Anyone please respond..
+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
Concurrency problems will arise. Please synchronize all the static methods in the DBUtils class.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hi Every one,

Please anyone guide me in when to use synchronization.Please provide any document.

Thanks In Advance
+Pie Number of slices to send: Send
Why is everything static? That's where the problem lies. Fix the problem, don't band-aid it with synchronization.
+Pie Number of slices to send: Send
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....

+Pie Number of slices to send: Send
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();
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
In DAO layer I call this method and get the connection object.Then in the DAO layer i'll close the connection.

No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2105 times.
Similar Threads
When do I need to be concerned with threading?
Help with a Build Error
Please help clarify this!
storing Resultset in a collection
Struts2 - Using ServletRequestAware is ok if we have multiple methods in action class?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:09:20.