We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 17c1c85 commit 50ecfa4Copy full SHA for 50ecfa4
Intervice/src/main/java/com/scma/synchronized_test/synchronizedTest.java
@@ -0,0 +1,27 @@
1
+package com.scma.synchronized_test;
2
+
3
+/*
4
+ * 关键字synchronized 原理
5
+ * */
6
+public class synchronizedTest implements Runnable {
7
+ public static int num = 0;
8
9
+ @Override
10
+ public void run() {
11
+ for (int i = 0; i < 1000; i++) {
12
+ num++;
13
+ }
14
15
16
+ public static void main(String[] args) {
17
+ for(int i=0;i<100;i++){
18
+ new Thread(new synchronizedTest()).start();
19
20
+ try {
21
+ Thread.sleep(2000); //等所有线程执行++ 操作完成
22
+ } catch ( Exception e) {
23
24
25
+ System.out.println(num);
26
27
+}
0 commit comments