發生java.lang.IllegalMonitorStateException 的通常緣由

是由於在調用notify或wait方法時,沒有獲取到對象鎖,好比這種寫法java

try {
            "".wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

只要改爲這樣既可code

try {
            String str="";
            synchronized (str){
                "".wait();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
相關文章
相關標籤/搜索