简体   繁体   English

集群环境中的Java静态变量

[英]Java static variable in cluster environment

Designing J2EE Applications for Real-Life Clustered Environments 为现实生活中的集群环境设计J2EE应用程序

this article said cannot use java static variable in cluster environment, but if we want to use the static variable like feature (only one copy of value shared by all object in a clustered application) what should we use? 本文说不能在集群环境中使用java静态变量,但是如果我们要使用静态变量之类的功能(集群应用程序中所有对象只能共享一个值的副本),我们应该使用什么?

A static variable can only be accesed by one Java Virtual Machine, loaded with one class loader. 静态变量只能由一台Java虚拟机访问,并由一个类加载器加载。 If you need to share this value to several JVM, you can use a database, a cache (memcached, redis), or any other external system. 如果需要将此值共享给多个JVM,则可以使用数据库,缓存(memcached,redis)或任何其他外部系统。

You can try to make it @Stateful bean with @javax.enterprise.context.ApplicationScoped . 您可以尝试使用@javax.enterprise.context.ApplicationScoped将其设置为@Stateful bean。

I haven't tried this, but it seems to me that GlassFish 3.1 should support it (at least the documentation does not deny it). 我没有尝试过,但是在我看来,GlassFish 3.1应该支持它(至少文档没有否认它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM