• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

update table and syncornization

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all:
When trying to update a table in a database, disrgarding the database setting, do we need to syncorize the updata code?
for example:
try
{
connection = getConnection(true);
syncornize(this){
statement = connection.createStatement();
result = statement.executeUpdate(sql);}
}
[ April 13, 2004: Message edited by: Hanna Habashy ]
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Locking, when it comes to DBs, is always better left to the Database. Consider the effect synchronized DB access will have on the performance of you application! Think why you would lock access when updating a row:
1. deadlock
2. race conditions
Deadlock is a very well understood problem in the world of RDBMSs. Its best left to them to handle possible collisions. Some are better then others (it takes more concurrent to cause a deadlock in Oracle than it does in SQL Server for example) but almost all are going to be better at handling this than you are in your code.
Race conditions are more common, since JDBC is usually used in a multiuser/multithread environment. In this case a locking startegy is a better route to protecting against the bugs race conditions can throw up. Optimistic locking works in most situations, and is a much better solution.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic