What happens when two thread calls static synchronized method?
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   RV_RamaKrishna
Posted On:   Friday, April 29, 2005 03:23 AM


When two threads say A,B are calling to a synchronized method which is declared as static synchronized say static synchronized Z(),which thread will acquire lock first.

Please gib a brief explanation.

Thanks in advance.

Re: What happens when two thread calls static synchronized method?

Posted By:   Anonymous  
Posted On:   Wednesday, May 11, 2005 04:07 PM

For aquiring a lock it doesn't matter weather the method is static or non-static.
In case of static synchronized methods you will have static monitors and non static synchronize methods associate object methods.

Re: What happens when two thread calls static synchronized method?

Posted By:   Victor_Ho  
Posted On:   Friday, April 29, 2005 04:41 PM

Which thread will acquire lock first?

- This depends on the thread scheduling (in most JVMs, it will be using native threads, in which the scheduling depends on the OS).


Note: A thread entering a synchronized static method will grab a lock on the class object (not instantied object).

Re: What happens when two thread calls static synchronized method?

Posted By:   WarnerJan_Veldhuis  
Posted On:   Friday, April 29, 2005 04:39 AM

The JVM will choose a thread that goes first. There is no guarantee that A will run before B or otherway around.... It does not matter if you instantiate Thread A first or Thread B. It's the JVM that manages thread-access...
About | Sitemap | Contact