问题描述
- EHCache报出java.lang.IllegalMonitorStateException异常
-
我写的代码如下所示,其中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)