private static String genServiceResponse(String url) {
        String resp = null;
        if (jmxUrl == null) {
            resp = statService.service(url);
        } else {
            if (conn == null) {// 连接在初始化时创建失败
                try {// 尝试重新连接
                    initJmxConn();
                } catch (IOException e) {
                    logger.error("init jmx connection error", e);
                    resp = DruidStatService.returnJSONResult(DruidStatService.RESULT_CODE_ERROR,
                            "init jmx connection error" + e.getMessage());
                }
                if (conn != null) {// 连接成功
                    try {
                        resp = getJmxResult(conn, url);
                    } catch (Exception e) {
                        logger.error("get jmx data error", e);
                        resp = DruidStatService.returnJSONResult(DruidStatService.RESULT_CODE_ERROR, "get data error:"
                                + e.getMessage());
                    }
                }
            } else {// 连接成功
                try {
                    resp = getJmxResult(conn, url);
                } catch (Exception e) {
                    logger.error("get jmx data error", e);
                    resp = DruidStatService.returnJSONResult(DruidStatService.RESULT_CODE_ERROR,
                            "get data error" + e.getMessage());
                }
            }
        }
        return resp;
    }
private static String genServiceResponse ( String url ) { String resp = null ; if ( jmxUrl == null ) { resp = statService . service ( url ) ; } else { if ( conn == null ) { try { initJmxConn ( ) ; } catch ( IOException e ) { logger . error ( "init jmx connection error" , e ) ; resp = DruidStatService . returnJSONResult ( DruidStatService . RESULT_CODE_ERROR , "init jmx connection error" + e . getMessage ( ) ) ; } if ( conn != null ) { try { resp = getJmxResult ( conn , url ) ; } catch ( Exception e ) { logger . error ( "get jmx data error" , e ) ; resp = DruidStatService . returnJSONResult ( DruidStatService . RESULT_CODE_ERROR , "get data error:" + e . getMessage ( ) ) ; } } } else { try { resp = getJmxResult ( conn , url ) ; } catch ( Exception e ) { logger . error ( "get jmx data error" , e ) ; resp = DruidStatService . returnJSONResult ( DruidStatService . RESULT_CODE_ERROR , "get data error" + e . getMessage ( ) ) ; } } } return resp ; }
程序首先判断是否存在jmx连接地址，如果不存在，则直接调用本地的duird服务； 如果存在，则调用远程jmx服务。在进行jmx通信，首先判断一下jmx连接是否已经建立成功，如果已经
建立成功，则直接进行通信，如果之前没有成功建立，则会尝试重新建立一遍。.

@param url 要连接的服务地址
@return 调用服务后返回的json字符串