Meaningless Drivel is fun!*
The moose likes Threads and Synchronization and the fly likes static synchronized method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "static synchronized method " Watch "static synchronized method " New topic

static synchronized method

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371

static synchronized int sumTotal() {


int getSalary() {


If two threads are trying to access sumTotal() at the same time, Whether Thread2 gets locked until Thread1 releases lock ?

Henry Wong

Joined: Sep 28, 2004
Posts: 18507

You have been asking a lot of simple thread questions lately. This is *not* the best way to learn threads, as threads is not just about the API.

For this question, why don't you tell us, what is it that you are confused with? And quite frankly, maybe it would be a good idea to start with the Sun tutorial on threads.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
public class Test implements Runnable {

public void run() {
Thread T1 = new Thread();
Thread T2 = new Thread();
Thread T3 = new Thread();
Thread T4 = new Thread();
Thread T5 = new Thread();


synchronized static int methA() {


synchronized int methB() {


static int methC() {


int methD() {


synchronized int methE() {



Using different threads(Thread1, Thread2, thread3, Thread4, Thread5) for each methods. Whether except Thread5, all other Threads run concurrently?

Don't get me started about those stupid light bulbs.
subject: static synchronized method
Similar Threads
What is the difference between these methods?
static synchronized block
tell me the differnce
Abstract class??
Can you synchronize an array?