Now i could't know Object's methods wait/notify/notifyall
when i use it ,it always throw a exception "Owner..Monitor..??"
give me a sample ,ok ?
[email protected]

解决方案 »

  1.   

    所有调用wait的函数好象必须写在同步函数(即有synchronized修饰的函数)中
      

  2.   

    再附一段代码:
        synchronized void addMessage(Message msg) {
            //<--测试代码
            parent.setStatusText("用户发出了一个请求。");
            // 测试代码-->
            msgs.addElement( msg );
            notify();
        }    synchronized Message getMessage() {
            while( msgs.isEmpty() ) {
                try {
                    wait(5000);
                } catch ( InterruptedException e) {}
            }        if ( msgs.isEmpty() )
                return null;        Message  msg = (Message)msgs.firstElement();
            msgs.removeElementAt( 0 );
            //<--测试代码
            parent.setStatusText("子线程准备处理用户的请求...");
            // 测试代码-->
            return msg;
        }
      

  3.   

        synchronized(this)
        {
           try
           {
              wait(); 
           }  
           catch(Exception ex_interrupt)
           {
               ....
           }
        } 
    Thank you very much for awake me.