本文介绍了线程中的静态同步和非静态同步方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以解释声明......静态同步方法和非静态同步方法不会相互阻塞 - 它们可以同时运行
can any one explain the statement ..."static synchronized method and non static synchronized method will not block each other -they can run at the same time"
推荐答案
静态方法和非静态方法的锁对象不同。静态方法使用Class对象作为锁(lock obj: MyClass.class
),而非静态方法使用实例对象作为锁的调用那时的方法是绑定的(锁定obj:这个
)。
The lock objects are different on the static method and non-static method. The static method uses the Class object as the lock (lock obj: MyClass.class
), while the non-static method uses the instance object as the lock to which the invocation of the method at that time is bound (lock obj: this
).
这篇关于线程中的静态同步和非静态同步方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!