获取 Glassfish2 域的名称
Glassfish v2 中是否可以获取当前域的名称?
我有这样的代码:
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
if (bean != null) {
MemoryUsage usage = bean.getNonHeapMemoryUsage();
int current = (int) ((double) usage.getUsed() / usage.getMax() * 100);
ch.log( Level.INFO, "Memory usage : (non heap) " + usage + " -- "+current+"% (limit:"+THRESHOLD+"%)");
if (current > THRESHOLD) {
//send email
}
当应用程序服务器即将崩溃时(PermGen 空间异常),它会向我们发送一封电子邮件;但我们已经运行了 3 个应用程序服务器,因此域名非常有用......知道吗?
谢谢
is it possible to get the name of the current domain in Glassfish v2?
I've got a code like:
MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
if (bean != null) {
MemoryUsage usage = bean.getNonHeapMemoryUsage();
int current = (int) ((double) usage.getUsed() / usage.getMax() * 100);
ch.log( Level.INFO, "Memory usage : (non heap) " + usage + " -- "+current+"% (limit:"+THRESHOLD+"%)");
if (current > THRESHOLD) {
//send email
}
which would send us an email when the appserver is about to crash (PermGen space exception); but we've got 3 appserver running, so the domain name would be really usefull ... any idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 AMX 获取域名。它可以从 DomainRoot 获取.getAppserverDomainName()。
You can use AMX to get the domain name. It is a available from DomainRoot.getAppserverDomainName().
这不是最漂亮的解决方案,但这个 hack 有效:
假设工作目录是 .../domains/domain/config
it's not the most beautifull solution, but this hack works:
provided that the working directory is .../domains/domain/config
你可以这样做:
hostname
等于“host:port”
,或者null
如果你想连接本地JVMyou can do it this way:
with
hostname
equals to"host:port"
, ornull
if you want to connect the the local JVM基于 Kevin 的答案,如果您只想通过使用 J2EEDomain mbean 上的 getPropertyValue 方法来使用 JMX(不依赖 AMX 库)。
Building on Kevin's answer, if you just want to use JMX (without relying on AMX libraries) just by using the getPropertyValue method on the J2EEDomain mbean.
这是我们一直在使用的一种非常简单的方法
Here's a really simple way that we've been using