zoukankan      html  css  js  c++  java
  • Java 获取weblogic 服务器IP和端口

    Java 获取weblogic 服务器IP、端口

    写了个定时任务,但是weblogic 服务器有好几台,代码放上去之后相当于多个定时任务同时运行,这不符合一开始的设计需求,因此需要指定一台服务器运行定时任务。代码如下:

    try {
    	Context ctx = new InitialContext();
    	MBeanServer tMBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
    	ObjectName tObjectName = new ObjectName("com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
    	ObjectName serverrt = (ObjectName) tMBeanServer.getAttribute(tObjectName, "ServerRuntime");
    	String port = String.valueOf(tMBeanServer.getAttribute(serverrt, "ListenPort"));
    	String listenAddr = (String) tMBeanServer.getAttribute(serverrt, "ListenAddress");
    	String[] tempAddr = listenAddr.split("/");
    	if (tempAddr.length == 1) {
    		listenAddr = tempAddr[0];
    	} else if (tempAddr[tempAddr.length - 1].trim().length() != 0) {
    		listenAddr = tempAddr[tempAddr.length - 1];
    	} else if (tempAddr.length > 2) {
    		listenAddr = tempAddr[tempAddr.length - 2];
    	}
    	log.warn(listenAddr + "++++++++++++++" + port);
    } catch (Exception e) {
    	e.printStackTrace();
    }
    
  • 相关阅读:
    Excel Sheet Column Number
    HappyNum
    isIsomorphic
    Contains DuplicateII
    iis7 设置http 自动跳转到https
    php 安装redis
    java 打包 war包
    NPOI 操作excel之 将图片插入到指定位置;
    nopi 简洁笔记
    vs11 微软下载地址
  • 原文地址:https://www.cnblogs.com/ghostwolf1/p/14839816.html
Copyright © 2011-2022 走看看