warace
2011-11-11 15:27
浏览 262
已采纳

问个多线程的问题

http://www.iteye.com/topic/44432

[code="java"]private Queue receivedData = new ArrayBlockingQueue(100);

public void receive(byte[] data, int length) {
    byte [] ldata = new byte[data.length+1];
    System.arraycopy(data, 0, ldata, 0, data.length);
    ldata[data.length]=(byte) length;
    this.receivedData.add(ldata);   

    synchronized(receivedData){                 
        this.receivedData.notify(); 
    }                       

}

private class HandlingThread implements Runnable{

    public void run() {     
        while(true){                
                if(!receivedData.isEmpty()){
                    byte[] data = receivedData.remove();                        
                    dealReceiveData(data);                  
                }                       
                else{
                    try {
                        synchronized(receivedData){
                            receivedData.wait();
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();

                    }
                }

        }
    }   

}[/code]

用的blockingqueue 但是我想当队列空的时候wait 怎么操作呢
这里回复都没解决问题

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题