Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Synchronization Problem whil accessing JDBC Code

 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 40
Eclipse IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never heard in a web application, static methods would access database.
Would like to know the responses though.

Anyone please respond..
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Concurrency problems will arise. Please synchronize all the static methods in the DBUtils class.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Every one,

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

Thanks In Advance
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is everything static? That's where the problem lies. Fix the problem, don't band-aid it with synchronization.
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....

 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In DAO layer I call this method and get the connection object.Then in the DAO layer i'll close the connection.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic