jQuery in Action, 2nd edition
The moose likes Threads and Synchronization and the fly likes static method and synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "static method and synchronized " Watch "static method and synchronized " New topic
Author

static method and synchronized

Viji San
Ranch Hand

Joined: Aug 12, 2010
Posts: 35
Do we need to use synchronized in the below static method code in multi threaded environment ?





}
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3670

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
jQuery in Action, 2nd edition
 
subject: static method and synchronized
 
Similar Threads
What is the difference between these methods?
static synchronized method?
synchronization not working properly
Random question
shared count variables for instances