Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update table and syncornization

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • 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 ]
 
eammon bannon
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic