EHCache报出java.lang.IllegalMonitorStateException异常 10C

我写的代码如下所示,其中EHCacheService.putIn是封装了EHCache的put函数,key=1,一直key++。
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class EHCacheTestCallable implements Callable {

@Override
public Object call() throws Exception {
    //for (int i = 0; i < thresd; i++) {
    for (int i = 0; ; i++) {
        EHCacheService.putIn("aba");
    }
}

public static void main(String[] args) {
    EHCacheTestCallable psc = new EHCacheTestCallable();
    ExecutorService es = Executors.newFixedThreadPool(1);
    @SuppressWarnings({ "unchecked", "unused" })
    Future recvHandler = es.submit(psc);
}

}
另外ehcache.xml中配置为:
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"
/>
存储的内容为一个字符串“aba”,存到2138639个的时候出现异常。
异常结果显示为:
Exception in thread "pool-1-thread-1" java.lang.IllegalMonitorStateException
at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)
at java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source)
at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

1个回答

抛出的异常表明某一线程已经试图等待对象的监视器,或者试图通知其他正在等待对象的监视器而本身没有指定监视器的线程。
调用Object.notify(), Object.notifyAll(), Object.wait(), Object.wait(long), Object.wait(long, int),这些方法时需要用synchronzied 关键字

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问