diff --git a/Java高级特性 - 多线程基础(3)线程同步.txt b/Java高级特性 - 多线程基础(3)线程同步.txt deleted file mode 100644 index 822cbad..0000000 --- a/Java高级特性 - 多线程基础(3)线程同步.txt +++ /dev/null @@ -1,36 +0,0 @@ -1.使用synchronized关键字同步线程 -package step2; - -public class Task { - - public static void main(String[] args) { - - final insertData insert = new insertData(); - - for (int i = 0; i < 3; i++) { - new Thread(new Runnable() { - public void run() { - insert.insert(Thread.currentThread()); - } - }).start(); - } - - } -} - -class insertData { - - public static int num = 0; - - /********* Begin *********/ - public synchronized void insert(Thread thread) { - - for (int i = 0; i <= 5; i++) { - num++; - System.out.println(num); - } - } - - /********* End *********/ -} -