Zookeeper循环注册监听器

Zookeeper中的监听器只执行一次,需要在watcher类中重写process方法,以达到重复注册监听器的效果

/**
     * 连接zk服务器
     * 
     */
    public static void connect()
    {
        LOGGER.info("**********begin to connect zookeeper*********");
        try
        {
            zk = new ZooKeeper(ZK_SERVER_URL, PropertyUtil.getDsfInt(ZK_SESSION_TIMEOUT_KEY, 3000), new Watcher()
            {
                // 监控所有被触发的事件
                public void process(WatchedEvent event)
                {
                    handle(event);
                }
                
            });
            
            getPreviewImage();
            LOGGER.info("********** connect zookeeper end*********");
        }
        catch (IOException e)
        {
            LOGGER.error("*******ZKUtil init error: ", e);
        }
    }

猜你喜欢

转载自www.cnblogs.com/jiliunyongjin/p/10906204.html
今日推荐