Java 刷新bean缓存
我正在使用一个使用EJB2的系统。该系统由两个独立的应用程序组成,一个用于用户管理,另一个是包含业务逻辑的实际应用程序 在业务逻辑应用程序中,我有一个bean管理的实体bean,它代表一个用户。 应用程序从用户管理数据库读取信息,但无法修改 无论何时在用户管理应用程序中修改用户,都会通知业务逻辑应用程序该用户已更改。这是作为对业务应用程序的调用来实现的,以删除bean,这会导致Weblogic将其从缓存中删除并“删除”它(什么都不做-请参阅下面的ejbRemove代码)。下次业务应用程序需要用户时,它将从数据库中重新加载该用户 我们使用以下代码使单个用户无效:Java 刷新bean缓存,java,caching,weblogic-10.x,ejb-2.x,Java,Caching,Weblogic 10.x,Ejb 2.x,我正在使用一个使用EJB2的系统。该系统由两个独立的应用程序组成,一个用于用户管理,另一个是包含业务逻辑的实际应用程序 在业务逻辑应用程序中,我有一个bean管理的实体bean,它代表一个用户。 应用程序从用户管理数据库读取信息,但无法修改 无论何时在用户管理应用程序中修改用户,都会通知业务逻辑应用程序该用户已更改。这是作为对业务应用程序的调用来实现的,以删除bean,这会导致Weblogic将其从缓存中删除并“删除”它(什么都不做-请参阅下面的ejbRemove代码)。下次业务应用程序需要用户
try
{
UserHome home = (UserAuthHome) getHome("User", UserHome.class);
User ua = home.findByPrimaryKey(user);
ua.remove(); // This will remove a single cached User bean in the business logic application
}
catch ...
这很好,但有时(尤其是在进行开发时)我需要使业务应用程序中所有缓存的用户bean无效。我希望以编程方式执行此操作-启动管理控制台花费的时间太长。用户太多,无法为每个用户进行呼叫
可能的解决办法包括:
--访问bean缓存并获取缓存用户bean的列表
--告诉WLS放弃当前用户bean缓存中的所有项,并从数据库中重新读取它们
不幸的是,我不知道如何做这两件事。
我试图寻找解决方案,但我的互联网搜索业没有发现任何有用的东西
其他信息:
持久性:
<persistence-type>Bean</persistence-type>
<reentrant>false</reentrant>
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>500</max-beans-in-cache>
<concurrency-strategy>Exclusive</concurrency-strategy>
<cache-between-transactions>true</cache-between-transactions>
</entity-cache>
<persistence></persistence>
</entity-descriptor>
public void ejbLoad()
{
thisLogger().entering(getUser(m_ctx), "ejbLoad()");
// Here comes some code that connects to the user database and fetches the bean data.
...
}
public void ejbRemove()
{
// This method does nothing
}
public void ejbStore()
{
// This method does nothing
}
public void ejbPostCreate()
{
// This method is empty
}
/**
* Required by EJB spec.
* <p>
* This method always throws CreateException since this entity is read only.
* The remote reference should be obtained by calling ejbFindByPrimaryKey().
*
* @return
* @exception CreateException
* Always thrown
*/
public String ejbCreate()
throws CreateException
{
throw new CreateException("This entity should be called via ejbFindByPrimaryKey()");
}
Bean
错误的
缓存:
<persistence-type>Bean</persistence-type>
<reentrant>false</reentrant>
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>500</max-beans-in-cache>
<concurrency-strategy>Exclusive</concurrency-strategy>
<cache-between-transactions>true</cache-between-transactions>
</entity-cache>
<persistence></persistence>
</entity-descriptor>
public void ejbLoad()
{
thisLogger().entering(getUser(m_ctx), "ejbLoad()");
// Here comes some code that connects to the user database and fetches the bean data.
...
}
public void ejbRemove()
{
// This method does nothing
}
public void ejbStore()
{
// This method does nothing
}
public void ejbPostCreate()
{
// This method is empty
}
/**
* Required by EJB spec.
* <p>
* This method always throws CreateException since this entity is read only.
* The remote reference should be obtained by calling ejbFindByPrimaryKey().
*
* @return
* @exception CreateException
* Always thrown
*/
public String ejbCreate()
throws CreateException
{
throw new CreateException("This entity should be called via ejbFindByPrimaryKey()");
}
500
独家
符合事实的
Bean代码(在业务应用程序中):
<persistence-type>Bean</persistence-type>
<reentrant>false</reentrant>
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>500</max-beans-in-cache>
<concurrency-strategy>Exclusive</concurrency-strategy>
<cache-between-transactions>true</cache-between-transactions>
</entity-cache>
<persistence></persistence>
</entity-descriptor>
public void ejbLoad()
{
thisLogger().entering(getUser(m_ctx), "ejbLoad()");
// Here comes some code that connects to the user database and fetches the bean data.
...
}
public void ejbRemove()
{
// This method does nothing
}
public void ejbStore()
{
// This method does nothing
}
public void ejbPostCreate()
{
// This method is empty
}
/**
* Required by EJB spec.
* <p>
* This method always throws CreateException since this entity is read only.
* The remote reference should be obtained by calling ejbFindByPrimaryKey().
*
* @return
* @exception CreateException
* Always thrown
*/
public String ejbCreate()
throws CreateException
{
throw new CreateException("This entity should be called via ejbFindByPrimaryKey()");
}
public void ejbLoad()
{
thisLogger()。输入(getUser(m_ctx),“ejbLoad()”;
//下面是一些连接到用户数据库并获取bean数据的代码。
...
}
公共void ejbRemove()
{
//这种方法不起任何作用
}
公共无效ejbStore()
{
//这种方法不起任何作用
}
public void ejbPostCreate()
{
//此方法为空
}
/**
*EJB规范要求。
*
*此方法始终引发CreateException,因为此实体是只读的。
*远程引用应通过调用ejbFindByPrimaryKey()获得。
*
*@返回
*@exception-CreateException
*总是扔
*/
公共字符串ejbCreate()
抛出CreateException
{
抛出新的CreateException(“应通过ejbFindByPrimaryKey()调用此实体”);
}
我做了一些额外的研究,找到了解决问题的方法
我能够使用weblogic.ejb.CachingHome.invalidateAll()
。然而,要做到这一点,我必须将bean的并发策略更改为ReadOnly
。显然,Exclusive
并发不会使主界面实现weblogic.ejb.CachingHome
:
<entity-descriptor>
<entity-cache>
<max-beans-in-cache>500</max-beans-in-cache>
<read-timeout-seconds>0</read-timeout-seconds>
<concurrency-strategy>ReadOnly</concurrency-strategy>
<cache-between-transactions>true</cache-between-transactions>
</entity-cache>
<persistence></persistence>
</entity-descriptor>