glassfish/tomcat Java Server 加载类一次
我正在使用 glassfish v2 但我在 tomcat 中遇到了同样的问题。
服务器启动后,我看到:
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;
现在的问题是一个类。当我调用 store 并使用servlet 获取时,我很好地收到了该对象。但是,对于两个类或 KVStore,servlet 在两者之间交替,并且在连续调用时永远不会正确返回。
现在我真的需要将对象存储在内存中。如何强制此类仅加载一次?或者创建一个全局可访问的哈希表?
最后一件事,我正在部署一个 jruby warbled war 文件。如果这种情况没有实际发生,请告诉我,我会对此进行调查。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以这不是一个完整的答案,因为我仍然有错误:
https://stackoverflow.com /questions/5785531/jruby-typeerror-assigning-non-exception-to
但是使用 jmap 我创建了一个单例。
如何在java中创建真正的单例?
具体来说:
< a href="http://surguy.net/articles/communication-across-classloaders.xml" rel="nofollow noreferrer">http://surguy.net/articles/communication-across-classloaders.xml
这是一个黑客。
So this is not a complete answer because I still have bugs:
https://stackoverflow.com/questions/5785531/jruby-typeerror-assigning-non-exception-to
But using jmap I have made a single singleton.
How to create a true singleton in java?
specifically:
http://surguy.net/articles/communication-across-classloaders.xml
which is a hack.
好吧,fml。最有可能你想要这个:
在你的 warble.rb 中并称其为好。
Ok, fml. Most likely you want this:
in your warble.rb and call it good.