This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
This has nothing to do with wether the methods are synchronized or not, this has something to do with static method calling non-static method and vice versa.
Answer is NO, static methods cannot call non-static methods directly. You can instantiate the class and use the object reference to make the call. By the way there a tricky way that you can get away with the syntax but it is not considered good coding style.
Like others have said, a static method cannot call a non-static method, whether it's synchronized or not. That's simple.
But it is possible for a non-static synchronized method to call a static synchronized method. However, the thread that's calling the static method may need to wait for the static method's lock to be released.
Static synchronized methods use the class's Class object as a lock. So the follow two methods are equivalent:
Non-static synchronized methods use the current object instance as a lock. So these two methods are equivalent:
SCJP 6 || SCWCD 5
Joined: May 18, 2005
Actually i meant to ask something different . Let me rephrase my question. Suppose a thread1 in non-static synchronized block,after acquiring object lock, calls a static synhronized method, then will thread1 acquire class lock or not, since a instance method can always call static method?