glassfish / tomcat Java服务器加载类一次 [英] glassfish/tomcat Java Server load class once
问题描述
服务器启动后,我看到:
sudo jmap -histo:live 14127 | grep KVStore
6222:1 24 xxx.xxx.KVStore
经过一段时间的使用后,我得到:
sudo jmap -histo:live 14127 | grep KVStore
7240:1 24 xxx.xxx.KVStore
7360:1 24 xxx.xxx.KVStore
虽然我猜这与glassfish的扩展有关,但这实际上是有问题的,因为我使用KVStore作为内存存储类。
它是一个带有静态哈希表以及getter和setter的单例类:
class KVStore
public static KVStore kvstore;
public Hashtable hash;
现在问题在于一个类。当我打电话给商店,并得到一个servelet我收到对象就好了。但是,使用两个类或KVStore时,servelet在两者之间交替,并且在连续调用时永远不会正确返回。
现在我真的需要将对象存储在内存中。我如何强制这个类只能加载一次?或者创建一个全局可访问的哈希表?
最后一件事,我正在部署一个jruby warbled war文件。如果没有这种可能发生的实际方式,请告诉我们,我会进行调查。
解决方案好的, FML。最有可能你想要这样:
config.webxml.jruby.min.runtimes = 1
config.webxml.jruby .max.runtimes = 1
放在warble.rb中,并称之为好。
I am using glassfish v2 but I've had the same problem in tomcat.
Once the server starts, I see:
sudo jmap -histo:live 14127 | grep KVStore
6222: 1 24 xxx.xxx.KVStore
After a while of usage, I get:
sudo jmap -histo:live 14127 | grep KVStore
7240: 1 24 xxx.xxx.KVStore
7360: 1 24 xxx.xxx.KVStore
While I'm guessing this has something to do with how glassfish scales out, this is really problematic because I use the KVStore as an in memory storage class.
It is a singleton class with a static hashtable and getters and setters:
class KVStore
public static KVStore kvstore;
public Hashtable hash;
Now the problem, is that with one class. When I call store and get with a servelet I receive the object just fine. But, with two classes or KVStore, the servelet alternates between the two and never returns correctly when the calls are made consecutively.
Now I really need to store the object in memory. How do I force this class to be loaded only once? Or create a Globally accessable hashtable?
One last thing, I am deploying a jruby warbled war file. If there is no actual way this could be happening, let me know and I'll look into that instead.
Ok, fml. Most likely you want this:
config.webxml.jruby.min.runtimes = 1
config.webxml.jruby.max.runtimes = 1
in your warble.rb and call it good.
这篇关于glassfish / tomcat Java服务器加载类一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!