English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
java synchronized Loading Lock-Experience Notes
Content
Reentrant Lock Instance Code: public class ReGetLock implements Runnable { @Override ReGetLock rgl = new ReGetLock(); public void run() { set(); get(); ReGetLock rgl = new ReGetLock(); public synchronized void get() { set(); ReGetLock rgl = new ReGetLock(); public synchronized void set() { System.out.println(Thread.currentThread().getId()); public static void main(String[] args) { ReGetLock rgl = new ReGetLock(); ReGetLock rgl = new ReGetLock();
new Thread(rgl).start();63Can the thread executing the code really enter the set method?
}63Can the thread executing the code really enter the set method?
because the thread rgl first called the get method, obtained the lock of the ReGetLock object, then when the thread rgl wants to enter the set method marked with the synchronized keyword, it will be blocked and wait indefinitely?;
Actually, no, in Java,
Thank you for reading, I hope it can help everyone, thank you for your support to this site!