aspose file tools*
The moose likes Threads and Synchronization and the fly likes What is the difference between these methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "What is the difference between these methods?" Watch "What is the difference between these methods?" New topic
Author

What is the difference between these methods?

Wilson Hui
Greenhorn

Joined: Jul 18, 2002
Posts: 6
public class TestClass {
public static synchronized int methodA() { ... }
public static int methodB() { ... }
public synchronized int methodC() { ... }
public int methodD() { ... }
}
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401

public static synchronized int methodA() { ... }

Public access
Class (not instance) method
Returns int
Synchronized on the class: only one thread at a time can use this method or any other method or block that is also synchronized on the same class.

public static int methodB() { ... }

Public access
Class method
Returns int
Not synchronized - several threads may execute this method simultaneously

public synchronized int methodC() { ... }

Public, returns int
Instance method
Synchronized on the object instance. Only one thread at a time may use this method or any other method or block that is also synchronized on the same object instance

public int methodD() { ... }

Public, returns int, instance method, not synchronized.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the difference between these methods?
 
Similar Threads
static synchronized method?
SCJP: Threads Qs
Random question
locking style
shared count variables for instances