如何跨多个EJB共享Java缓存系统(JCS)资源 [英] How do you share Java Caching System (JCS) resource across multiple EJB

查看:143
本文介绍了如何跨多个EJB共享Java缓存系统(JCS)资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JCS来存储应该由多个EJB共享的ldap搜索结果。我创建了一个singleton类来仅初始化JCS,但由于EJB的类加载器,它已用自己的副本多次初始化。所以搜索资源不共享。



你们如何解决需要跨多个bean共享缓存的问题?
我正在寻找JVM中的缓存。 (不是远程的,例如memcached等)。

Glassfish被用作应用程序服务器。

解决方案

我还没有测试过它,但我认为应用程序开发指南中的避开类加载程序隔离一章,您正在使用的Glassfish版本可能会解决您的问题。






短版本,至少对2-3-4版本有效:使用Common Classloader(这个普通的类加载器究竟做了什么以及它与其他的关系类加载器在相同的手册中解释)。有几种方法可以做到这一点:




  • 将jar复制到 domain-dir / lib

  • 或将jar复制到 as-install / lib

  • 或运行 asadmin add-library --type common /path/to/your.jar (仅适用于版本4 iirc)



关于SO的几个问题与避开类加载程序隔离(仅使用该搜索字词)有关,请查看示例和更多讨论。


I am using JCS to store the ldap search results which should be shared by multiple EJB. I have created a singleton class to initialize JCS only once but due to EJB's classloader, it's been initialized multiple times with its own copy. so search resources are not shared.

How are you guys resolving issue where you need to share the cache across multiple beans? I am looking for cache within JVM. (Not the remote e.g memcached etc.).

Glassfish is used as an application server.

解决方案

I haven't been able to test it yet, but I think that one of the techniques explained in the "Circumventing Class Loader Isolation" chapter of the Application Development Guide for the version of Glassfish you are using may solve you problem.


Short version, at least valid for versions 2-3-4 : use the Common Classloader (what exactly this common classloader does and its relation to the other classloaders is explained in the same manual). There are several ways to do this:

  • copy the jar to domain-dir/lib
  • or copy the jar to as-install/lib
  • or run asadmin add-library --type common /path/to/your.jar (will only work in version 4 iirc)

There are several questions here on SO that are related to "Circumventing Class Loader Isolation" (just use that search term), look there for examples and more discussion.

这篇关于如何跨多个EJB共享Java缓存系统(JCS)资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆