Java:synchronized???????????????
???????????? ???????[ 2012/11/19 9:50:28 ] ????????
??????Java?У?synchronized?????????????????????????????????????£?????synchronized????β?????????????С?Synchronized?????????????????????????????????
?????????????????????????????μ???synchronized???′???????????δ???
class Sync {
public synchronized void test() {
System.out.println("test???..");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("test????..");
}
}
class MyThread extends Thread {
public void run() {
Sync sync = new Sync();
sync.test();
}
}
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
Thread thread = new MyThread();
thread.start();
}
}
}
???????н????
????test???..
????test???..
????test???..
????test????..
????test????..
????test????..
?????????????????????????????????????????test?????????test??????????synchronized?????????????????????ò??synchronized??????á?
??????test??????????£?
public void test() {
synchronized(this){
System.out.println("test???..");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("test????..");
}
}
???????н????
????test???..
????test???..
????test???..
????test????..
????test????..
????test????..
??????л?????????????п???synchronized???????á?
??????????synchronized(this)?????static??synchronized??????????static synchronized???????????????????????????????????????????????Ρ?
??????????????????????????????Java????????synchronized????????????????????synchronized???????????????????????????????????synchronized????????????????????this??
??????synchronized?????????????????????????????????????????????????????????????????????θ?????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11