管程是指由synchronized修饰的线程 在同一时间内只能有一个线程 对该方法进行访问
只有当一个线程结束对该方法的访问后 下一个线程才能对其访问

解决方案 »

  1.   

    找一本java书籍看看吧,多线程那一部分内容,将使你想要弄明白的地方!
      

  2.   


    wait是暂停一个线程
    notify继续进程
    例如:(尚未测试)
    class a extends Thread{
       boolean st=false;    //线程处于启动状态
       a(String tn){      
          super(tn);        //线程名称
          start();
       }
       public void run() throws Exception{
          
          for (int i=0;i<50;i++){
             System.out.println(i);
             Thread.sleep(100)
             synchronized(this){          //处理线程同步
                while(st){
                   wait();                //暂停线程
                }
              }
          }
       }
       public void stopT(){
          st=true;
       }
       public void startT(){         //叫醒线程
          st=false;
          notify();
       }
    }运用------------------------------------------------
    public class userThread{
       public static void main(String[] args) throws Exception{
          a t1=new a("Thread1");
          a t2=new a("thread2");
          t1.stopT();
          Thread.sleep(500);
          t1.startT();
       }}
      

  3.   

    Java里的wait(),notify()以及notifyAll()涉及到parallel programming里的Monitor概念,找一本这方面的书看看,就能更深刻地理解这些函数的运用了.