IllegalMonitorStateException异常

ApacheHttpClient类中init初始化方法报错 IllegalMonitorStateException

具体是 this.latch.wait();执行wait()报错

public void init(final HttpClientConfig config) throws ClientException {
        if (!this.initialized.compareAndSet(false, true)) {
            try {
                this.latch.wait();
            } catch (InterruptedException var5) {
                throw new ClientException("SDK.InitFailed", "Init apacheHttpClient failed", var5);
            }
        }
}

解决办法是: 

ApacheHttpClient.getInstance();的使用结束之后调用close()方法!
ApacheHttpClient.getInstance().close();

此方法从java.io.Closeable获得
关闭资源即可

关于IllegalMonitorStateException异常的解释
转载: https://blog.csdn.net/wangshuang1631/article/details/53815519

抛出该异常表明某一线程已经试图等待对象的监视器,或者试图通知其他正在等待对象的监视器,然而本身没有指定的监视器的线程。
原文地址:https://www.cnblogs.com/yxgmagic/p/13611484.html