participate


New To Java - synchronisation methods in same class
This question is answered.

<<   Back to Forum  |   Give us Feedback
10 Duke Stars rewarded for this thread
This topic has 6 replies on 1 page.
smita_smita
Posts:502
Registered: 12/16/04
synchronisation methods in same class   
Nov 7, 2009 7:49 AM
 
 
I have three methods in same class A,B,C IN which A,B synchronised and c not.
my question is if one thread is in A.another thread cann access B OR C?
 
DarrylBurke
Posts:15,598
Registered: 7/2/07
Re: synchronisation methods in same class   
Nov 7, 2009 9:18 AM (reply 1 of 6)  (In reply to original post )
 
 
You tell us. After all, it's your homework.

db
 
jverd
Posts:51,846
Registered: 3/30/99
Re: synchronisation methods in same class   
Nov 7, 2009 9:51 AM (reply 2 of 6)  (In reply to original post )
 
 
Syncing a block on the object pointed to by X
synchronized (X) { /* do stuff */}

simply waits until no other thread is synced on that object, and then enters the block.

Declaring a non-static method synchronized is the same as doing
synchronized (this) { /* do stuff */ }


Calling a non-synced method or executing a non-synced block or statement does not wait for the lock.
 
georgemc
Posts:16,804
Registered: 5/8/06
Re: synchronisation methods in same class   
Nov 7, 2009 9:59 AM (reply 3 of 6)  (In reply to #2 )
 
 
jverd wrote:
Syncing a block on the object pointed to by X
synchronized (X) { /* do stuff */}

simply waits until no other thread is synced on that object, and then enters the block.

Declaring a non-static method synchronized is the same as doing
synchronized (this) { /* do stuff */ }


Calling a non-synced method or executing a non-synced block or statement does not wait for the lock.

Duke-wh0ring?? :)
 
jverd
Posts:51,846
Registered: 3/30/99
Re: synchronisation methods in same class   
Nov 7, 2009 10:03 AM (reply 4 of 6)  (In reply to #3 )
 
 
georgemc wrote:
Duke-wh0ring?? :)

Totally. I need to build up a nest egg for when I retire.
 
smita_smita
Posts:502
Registered: 12/16/04
Re: synchronisation methods in same class   
Nov 7, 2009 10:28 AM (reply 5 of 6)  (In reply to #3 )
 
 
no synchronized block.all are synchronized methods.
synchronized method A()
synchronized method b()
method c()
two threads t1 and t2
t1 accesses method A()
whether t2 can access the method B or NOT? while T1 in A().
Thanks
 
jverd
Posts:51,846
Registered: 3/30/99
Re: synchronisation methods in same class      
Nov 7, 2009 10:39 AM (reply 6 of 6)  (In reply to #5 )
Helpful
 
smita_smita wrote:
no synchronized block.all are synchronized methods.

Doesn't matter. My explanation covers both.

synchronized method A()
synchronized method b()
method c()
two threads t1 and t2
t1 accesses method A()
whether t2 can access the method B or NOT? while T1 in A().

I answered your question.

And this is a multithreading question that's actually very easy to test with code.
 
This topic has 6 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums