2012-09-07 100 views
0
CacheManager的初始化錯誤

我在谷歌應用程序引擎V1.7.0使用的EHCache 2.6.0編程方式(沒有ehcache.xml中)。GAE上的EHCache

當我實例的CacheManager使用:

CacheManager cacheManager = CacheManager.create(); 

我得到錯誤:

Caused by: java.lang.RuntimeException: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers) 
    at java.util.concurrent.atomic.AtomicReferenceFieldUpdater$AtomicReferenceFieldUpdaterImpl.<init>(AtomicReferenceFieldUpdater.java:217) 
    at java.util.concurrent.atomic.AtomicRefe...(length 9029) 

我想:

CacheManager cacheManager = new CacheManager(); 

,並與監測關:

Configuration configuration = new Configuration(); 
configuration.setMonitoring(Configuration.Monitoring.OFF.name()); 
configuration.setUpdateCheck(false); 
CacheManager cacheManager = new CacheManager(configuration); 

爲他們兩個我有以下錯誤:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.ehcache.util.lang.VicariousThreadLocal 
    at net.sf.ehcache.TransactionController.<init>(TransactionController.java:43) 
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:433) 
    at net.sf.ehcache.CacheManager.init(CacheManager.java:374) 

如何解決這個問題?

回答

1

應用服務引擎是一種分佈式系統,其中請求被自動多個前端實例處理。在這樣的設置,你不能使用在前端實例緩存實現(的EHCache),因爲你將有運行的EHCache的多個實例,寫一個的EHCache不會對其他EHCaches反映。

相反,你應該使用AppEngine上自己的memcache service

+0

但提供的EHCache GAE支持,請參閱[鏈接](http://ehcache.org/documentation/integrations/googleappengine) –

+0

OK,在這種情況下,它似乎的EHCache包裝GAE緩存。但是,你需要適當的配置:http://ehcache.org/documentation/integrations/googleappengine#configuring-ehcachexml –

+0

「兼容性 的Ehcache是​​兼容的,與谷歌應用程序引擎谷歌App Engine提供一個約束的運行制約網絡工程,線程和文件系統訪問「。 。網絡限制意味着它不會被分發。如果我錯了,請糾正我! –

3

在我看來,那的Ehcache V2.6是與當前的AppEngine兼容。我不得不切換到以前版本的ehcache才能運行。經過漫長的嘗試和錯誤2.4.7版本似乎是穩定的。 '顯然'由ehcache提供的配置不起作用。這裏是我不得不對其進行配置:

<?xml version="1.0" encoding="UTF-8"?> 
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="ehcache.xsd" > 
    <cacheManagerEventListenerFactory class="" properties=""/> 
    <defaultCache 
     maxElementsInMemory="10000" 
     eternal="false" 
     overflowToDisk="false" 
     timeToIdleSeconds="120" 
     timeToLiveSeconds="120" 
     memoryStoreEvictionPolicy="LRU"> 
    </defaultCache> 
<!--Example sample cache--> 
    <cache name="sid" 
     maxElementsInMemory="100" 
     eternal="false" 
     timeToIdleSeconds="300" 
     timeToLiveSeconds="300" 
     memoryStoreEvictionPolicy="LFU" 
     /> 
</ehcache>