[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6871) SingletonEhCacheProvider shoud not shutdown singleton CacheManager if it doesn't own it

Adrien (JIRA) noreply at atlassian.com
Fri Dec 30 23:48:19 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6871?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44799#comment-44799 ] 

Adrien commented on HHH-6871:
-----------------------------

> there is not a way for use to know if that CacheManager already existed when we initially spin up the first time.

CacheManager.getCacheManager(null) return null if the singleton is not already initialized.

> on a Hibernate-specific variable 

No. You already have a REFERENCE_COUNT. When you access it for the first time (REFERENCE_COUNT.get() == 0), we could check if the singleton is already initialized (CacheManager.getCacheManager(null) != null), meaning it is used by someelse. In that case, we acknowledged the fact that it is used by someone outside Hibernate by incrementing the REFERENCE_COUNT.

> Why not just plug in a custom 2nd-level-cache RegionFactory that does what you need for your environment?

I fixed the problem for me, but I lost some time finding out who was destroying my CacheManager singleton. 

> SingletonEhCacheProvider shoud not shutdown singleton CacheManager if it doesn't own it
> ---------------------------------------------------------------------------------------
>
>                 Key: HHH-6871
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6871
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: caching (L2)
>    Affects Versions: 3.6.8, 4.0.0.CR7
>            Reporter: Adrien
>            Priority: Minor
>              Labels: ehcache
>             Fix For: 4.0.1
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> SingletonEhCacheProvider use a static referenceCount every time a sessionFactory wants a CacheManager, and shutdown it when all sessionFactories are gone. But Hibernate may not be the only one using it. In our case, we have manual configuration of the CacheManager singleton and cache regions not managed by Hibernate. The simple fact of creating a SessionFactory, then close it shutdown the singleton, with our configuration and cache regions.
> It's hard to know if Hibernate is the only one using EhCache and it's cool that Hibernate close the EhCache threads for most configurations, but in our case, it's a real problem. We manually call new SingletonEhCacheProvider().start(null) to increment the referenceCount, but others will have the problem.
> My proposition is that before accessing for the first time to the CacheManager (referenceCount, Hibernate check if it's already exist (meaning it's already been used by someoneelse). If so, it increment the referenceCount to be sure Hibernate will never shutdown the CacheManager. Something like :
> public void start(Settings settings, Properties properties) throws CacheException {
>   (...)
>   if (referenceCount.get() == 0 && CacheManager.getCacheManager(null) != null) {
>     REFERENCE_COUNT.incrementAndGet();
>   }
>   (...)
> }
> There may be some multi-thread issues with this code, but it's just the idea.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list