multiThreading

https://www.cnblogs.com/pureEve/p/6524366.html

创建新线程

https://www.cnblogs.com/xwlych/p/5988507.html

线程同步与互斥

https://blog.csdn.net/dazhong159/article/details/7927034

https://www.cnblogs.com/mithrandirw/p/8942335.html

java中的sleep()和wait()的区别

https://www.cnblogs.com/hongten/p/hongten_java_sleep_wait.html

 1 public class Main {
 2     static int sum =1000;
 3     static int a=0;
 4     static int b=0;
 5     static int flag=0;
 6     public static void main(String[] args) {
 7         Thread1 thread1=new Thread1("a");
 8         thread1.setPriority(3);
 9         Thread1 thread2=new Thread1("b");
10         thread2.setPriority(7);        
11         thread2.start();
12         thread1.start();
13     }    
14     private static class Thread1 extends Thread{
15         public Thread1(String name) {
16             super(name);
17         }
18         @Override
19         public void run(){
20             while(sum>0){
21                 synchronized (Main.class) {            
22                     if(getName()=="a") {
23                         a++;
24                         sum--;
25                         System.out.println("a:"+a);
26                         System.out.println("sum:"+sum);
27                     }
28                     else if(getName()=="b") {
29                         b++;
30                         sum--;
31                         System.out.println("b:"+b);
32                         System.out.println("sum:"+sum);
33                     }
34                     if(sum<=100&&flag==1) {
35                         Main.class.notify();
36                         flag=2;
37                         System.out.println("end-----------------------------------------------------");
38                     }
39                     if(sum<=900&&flag==0) {
40                         if(getName()=="b") {
41                             System.out.println("start------------------------------------------------");
42                             flag=1;
43                             try {
44                                 Main.class.wait();
45                             } catch (InterruptedException e) {
46                                 // TODO Auto-generated catch block
47                                 e.printStackTrace();
48                             }
49                         }
50                     }
51                 }
52             }          
53         }
54     }
55 }

原文地址:https://www.cnblogs.com/DixinFan/p/9126352.html