读取webserver 里的queue

说笨还嘴硬不肯不承认,看吧,读取queue用parse xml的方法多傻呀,万一web server不是jboss就得满处找配置文件了,而且文件名还被我很蠢地固化到了程序中(懒得再增加一个property文件)。

××××××××××××× 问题解决的分隔线 ×××××××××××××××

好了,这下终于用读取JNDI的方法解决了。

因为和queue进行连接的时候首先要做的一步是在context里根据jndi进行lookup,所以直接读取jndi的list即可得到包括queue在内的所有值。

剩下的就只是挑选出需要用的queue。

代码如下:

protected String[] getQueueListFromJNDI() throws ServletException {       
        Vector ql = new Vector(0);
        int qlLength = 0;
        try{           
            InitialContext ctx = new InitialContext();
            NamingEnumeration en = ctx.list( "queue" );
            while(en.hasMoreElements()) {
                NameClassPair nc = (NameClassPair)en.nextElement();               
                ql.addElement(nc.getName());
                qlLength ++;
            }
            ctx.close();
        } catch(NamingException e) {
            e.printStackTrace();
        }       
        String[] queueList = new String[qlLength];
        for(int i = 0; i < qlLength; i ++ ){
            queueList[i] = (String)ql.elementAt(i);
        }       
        return queueList;
    }

 

编写+查阅API资料耗时2小时,而上次的xml解析耗时……8小时 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值