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

Steve Ebersole (JIRA) noreply at atlassian.com
Fri Dec 30 22:43:19 EST 2011


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

Steve Ebersole commented on HHH-6871:
-------------------------------------

Unless I am misunderstanding you, there is not a way for use to know if that CacheManager already existed when we initially spin up the first time.  You are (I believe) expecting us to base this on a Hibernate-specific variable that someone else (Ehcahce? you?) happens to also update?  That sounds scary.

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

Let me know if I misunderstood.

> 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