• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronized method question.  RSS feed

 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all.
I am not quite sure about how synchronized method works in the following case, please confirm my thought.
class A {
synchronized static void m1() {
}
synchronized static void m2() {
m1();
}
}
In this example, since they are synchronized static methods, only one copy of method of A can exist anytime in the system, right? However is it allowed for m2() to call m1()? I think it's ok, is that true? Thanks
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but test it to see the repercussions.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
Yes, it's true. But Bill is right too by suggesting you to test it.
Best,
Phil.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!