-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: multiple thread problem with EHCache
PostPosted: Fri Oct 29, 2004 2:43 pm 
Regular
Regular

Joined: Tue Nov 11, 2003 7:35 pm
Posts: 63
Hibernate version: 2.1.6 and EHCache version 1.0

Hi All,

I seem to be having a multiple thread problem instantiating a cache. If multiple threads try to create a cache at the very same moment I get the following exception:

Code:
net.sf.hibernate.cache.CacheException: net.sf.ehcache.ObjectExistsException: Cache WhateverCache already exists


I think this would happen in general but specifially in my case it happens if I try to use a query cache in Hibernate. I am doing the following:

Code:
Query query = session.createQuery("some query");
query.setCacheable(true);
query.setCacheRegion("WhateverCache");
return query.list();


if this block of code gets executed simultaniously by more than one thread it results in the exception.

The same session is NOT used for both threads, i.e. each thread has its own session.

Is this a bug in Hibernate or EHCache? Perhaps there needs to be some syncronization code somewhere.

Here is more of the stack trace:

Code:
net.sf.hibernate.cache.CacheException: net.sf.ehcache.ObjectExistsException: Cache WhateverCache already exists
at net.sf.hibernate.cache.EhCache.<init>(EhCache.java:101)
at net.sf.hibernate.cache.EhCacheProvider.buildCache(EhCacheProvider.java:84)
at net.sf.hibernate.cache.StandardQueryCache.<init>(StandardQueryCache.java:42)
at net.sf.hibernate.cache.StandardQueryCacheFactory.getQueryCache(StandardQueryCacheFactory.java:19)
at net.sf.hibernate.impl.SessionFactoryImpl.getQueryCache(SessionFactoryImpl.java:637)
at net.sf.hibernate.loader.Loader.list(Loader.java:1011)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)


Thank you,
Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 3:17 pm 
Regular
Regular

Joined: Tue Nov 11, 2003 7:35 pm
Posts: 63
One thing I would like to add is that I do not have an entry in my ehcache.xml for this cache and therefore the cache gets created as the query executes. If it was in the ehcache.xml file the cache would have already been created at startup of ehcache and the problem would not occur.

Nevertheless I still believe it is a bug in the case where the cache is not in the ehcache.xml file.


Top
 Profile  
 
 Post subject: Re: multiple thread problem with EHCache
PostPosted: Thu Feb 26, 2015 10:14 am 
Newbie

Joined: Thu Feb 26, 2015 10:09 am
Posts: 1
Hi, I have the same problem. I am using multi threads. My ehcache configuration is ok for one thread, but for multi threads my app has to hit again the database and it does not consult ehcache. What configuration I am missing?

Here is my ehcache.xml. Thanks!

Code:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
   monitoring="autodetect" dynamicConfig="true">

   <diskStore path="user.dir/ehcache" />

   <defaultCache maxEntriesLocalHeap="10000" eternal="false"
      timeToIdleSeconds="0" timeToLiveSeconds="1800" diskSpoolBufferSizeMB="80"
      maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
      memoryStoreEvictionPolicy="LRU" statistics="true">
      <persistence strategy="localTempSwap" />
   </defaultCache>

   <cache name="blockiscsi" maxEntriesLocalHeap="10000" eternal="false"
      timeToIdleSeconds="5" timeToLiveSeconds="10">
      <persistence strategy="localTempSwap" />
   </cache>

   <cache name="org.hibernate.cache.internal.StandardQueryCache"
      maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="120">
      <persistence strategy="localTempSwap" />
   </cache>

   <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
      maxEntriesLocalHeap="5000" eternal="true">
      <persistence strategy="localTempSwap" />
   </cache>
</ehcache>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.