This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static method and synchronized

 
Viji San
Ranch Hand
Posts: 35
  • 0
  • 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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • 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: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic