如何在Wildfly中对应用程序作用域状态进行聚类? [英] How can I cluster application-scope state in wildfly?

查看:67
本文介绍了如何在Wildfly中对应用程序作用域状态进行聚类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对保留在应用程序级范围内的地图进行聚类.

I would like to cluster a map that is kept on application-level scope.

首先想到的是将@Singleton@Clustered bean与包含我的数据的字段一起使用.
这似乎不起作用,我的猜测是它是

A first thought was to use a @Singleton, @Clustered bean with a field holding my data.
This does not seem to work and my guess is that it was never implemented

这篇文章提出了实现集群单例的方法,但它们看起来很复杂.

This post proposes ways to implement clustered singletons but they seem complex.

除了手动更新数据库表之外,我看到的唯一替代方法是使用复制的缓存.

The only alternative that I see, apart from manually updating db table(s), is to use a replicated cache.

我的问题是:是否建议声明和使用infinispan缓存(例如

My question is: Is it advised to declare and use an infinispan cache (like this) for solving this problem?
If yes, what settings should I use to avoid dirty reads?
Is there any other option to this relatively simple problem in the era of wildfly-18?

推荐答案

正如您提到的集群,您需要使用standalone-full-ha.xml

As you mentioned a cluster, you need to use standalone-full-ha.xml

编辑文件并添加以下配置

Edit the file and add the following configuration

<cache-container module="org.infinispan.extension" name="infinispan_container" default-cache="default">
    <transport lock-timeout="60000"/>
    <global-state/>
    <distributed-cache name="default"/>
    <local-cache name="localCache"/>
    <replicated-cache name="replicatedCache"/>
</cache-container>

您可以为应用程序使用不同的缓存,如果您希望使用复制的缓存,则可以通过以下方式将其注入应用程序中

You have different caches available for your application, if you wish use a replicated cache, you can inject it in your app with

@Resource(lookup = "java:jboss/datagrid-infinispan/container/infinispan_container/cache/replicatedCache")
Cache cache;

这篇关于如何在Wildfly中对应用程序作用域状态进行聚类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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