File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes static method and synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
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: 3775

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: 19545
    
  16

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static method and synchronized
 
Similar Threads
Random question
shared count variables for instances
What is the difference between these methods?
static synchronized method?
synchronization not working properly