Java??????????synchronized???
???????????? ???????[ 2014/5/13 15:16:34 ] ????????Java????? ???????????
????1.?????з????????
????synchronized????????????????????????????????????synchronized????????????????synchronized???????????????????
??????????
public class ThreadTest {
public static void main(String[] args) {
Stu stu = new Stu();
StuThread1 t1 = new StuThread1(stu);
t1.start();
StuThread2 t2 = new StuThread2(stu);
t2.start();
}
}
class StuThread1 extends Thread {
Stu stu;
public StuThread1(Stu stu) {
this.stu = stu;
}
public void run() {
stu.read1();
}
}
class StuThread2 extends Thread {
Stu stu;
public StuThread2(Stu stu) {
this.stu = stu;
}
public void run() {
stu.read2();
}
}
class Stu {
public synchronized void read1() {
System.out.println("read1 begin");
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("read1 end");
}
public synchronized void read2() {
System.out.println("read2 begin");
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("read2 end");
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
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