Java????????Synchronized??????????
???????????? ???????[ 2016/4/29 13:41:48 ] ??????????????????? Java
????3????????????????
?????????????
1 package com.paddx.test.concurrent;
2
3 public class SynchronizedTest {
4 public static synchronized void method1(){
5 System.out.println("Method 1 start");
6 try {
7 System.out.println("Method 1 execute");
8 Thread.sleep(3000);
9 } catch (InterruptedException e) {
10 e.printStackTrace();
11 }
12 System.out.println("Method 1 end");
13 }
14
15 public static synchronized void method2(){
16 System.out.println("Method 2 start");
17 try {
18 System.out.println("Method 2 execute");
19 Thread.sleep(1000);
20 } catch (InterruptedException e) {
21 e.printStackTrace();
22 }
23 System.out.println("Method 2 end");
24 }
25
26 public static void main(String[] args) {
27 final SynchronizedTest test = new SynchronizedTest();
28 final SynchronizedTest test2 = new SynchronizedTest();
29
30 new Thread(new Runnable() {
31 @Override
32 public void run() {
33 test.method1();
34 }
35 }).start();
36
37 new Thread(new Runnable() {
38 @Override
39 public void run() {
40 test2.method2();
41 }
42 }).start();
43 }
44 }
??????н?????£???????????????????????????????????????????????????????????????????????????????????test??test2????????????????????????SynchronizedTest???????????????????????method1??method2???????????С?
????Method 1 start
????Method 1 execute
????Method 1 end
????Method 2 start
????Method 2 execute
????Method 2 end
????4??????????
????????????
1 package com.paddx.test.concurrent;
2
3 public class SynchronizedTest {
4 public void method1(){
5 System.out.println("Method 1 start");
6 try {
7 synchronized (this) {
8 System.out.println("Method 1 execute");
9 Thread.sleep(3000);
10 }
11 } catch (InterruptedException e) {
12 e.printStackTrace();
13 }
14 System.out.println("Method 1 end");
15 }
16
17 public void method2(){
18 System.out.println("Method 2 start");
19 try {
20 synchronized (this) {
21 System.out.println("Method 2 execute");
22 Thread.sleep(1000);
23 }
24 } catch (InterruptedException e) {
25 e.printStackTrace();
26 }
27 System.out.println("Method 2 end");
28 }
29
30 public static void main(String[] args) {
31 final SynchronizedTest test = new SynchronizedTest();
32
33 new Thread(new Runnable() {
34 @Override
35 public void run() {
36 test.method1();
37 }
38 }).start();
39
40 new Thread(new Runnable() {
41 @Override
42 public void run() {
43 test.method2();
44 }
45 }).start();
46 }
47 }
??????н?????£???????1?????2????????????????????У????????2???????????????????????1????????????ɡ?
????Method 1 start
????Method 1 execute
????Method 2 start
????Method 1 end
????Method 2 execute
????Method 2 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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????