对于这样的一个应用场景,一个主线程维护着一个应用服务,可以将这个线程设置为等待,注意要写在循环体中。在其他线程调用此对象的Notify()方法或NotifyAll()方法前,导致当前线程一直运行没有结束,维护的应用服务一下正常运行,这个就可以一直使用应用服务。 synchronized (AliasMappingServerMain.class) { while (true) { try { AliasMappingServerMain.class.wait(); } catch (InterruptedException e) { } } }