Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method and synchronized

 
Viji San
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do we need to use synchronized in the below static method code in multi threaded environment ?





}
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viji San wrote:Do we need to use synchronized in the below static method code in multi threaded environment ?...

Can't tell much about it with the given code, anyway if the data (used in this scenario) are being manipulated by multiple programs you should synchronize the access to those data.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends. You need to have some form of synchronization, but perhaps it's a better idea to do it in the database, perhaps with a stored procedure. That way your requests are thread safe even outside your Java program.

If you decide to do it in Java, don't synchronize this method. It will still be possible to execute the same query by calling DataBaseManager.getdb().executeQuery("GETSEQUENCE") directly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic