java没有线程等待,使用notify会抛异常吗?

答案是不会的,我已经试过了,代码如下:

public class TestNotify {

    public static void main(String[] args) {
        
        TestNotify testNofify = new TestNotify();
        
        testNofify.testNotify();
        
    }
    
    public void testNotify() {
        synchronized (this) {
            
            this.notify();
            System.out.println(this);
            
        }
    }

    @Override
    public String toString() {
        return "testNotify";
    }
    
    
    
}

  程序能正常打印并且结束,没有出现任何异常

posted @ 2020-09-26 19:25  爱编程DE文兄  阅读(291)  评论(0编辑  收藏  举报