zoukankan      html  css  js  c++  java
  • zookeeper-API相关操作-修改节点

    工程具体结构见上文

    https://www.cnblogs.com/aoligei/p/15010287.html

      //======================================set============================
    
        /**
         * 修改数据
         * 1.修改数据 client.getData().forPath("/test1");
         * 2.根据版本修改(多线程环境下 ABA 问题) client.setData().withVersion(version).forPath("/test2", "A".getBytes());
         * version 是通过查询出来的,目的就是不受其他客户端或者线程的干扰
         * @throws Exception
         */
        @Test
        public void testSet1() throws Exception {
            client.setData().forPath("/test1", "set1".getBytes());
            byte[] bytes = client.getData().forPath("/test1");
            System.out.println(new String(bytes));
        }
    
        @Test
        //ABA问题
        public void testSetForversion() throws Exception {
            Stat status = new Stat();
            client.getData().storingStatIn(status).forPath("/test2");
            int version = status.getVersion();
            System.out.println(version);
            client.setData().withVersion(version).forPath("/test2", "A".getBytes());
    
        }

    1、修改数据

    2、根据版本修改数据

     

  • 相关阅读:
    缓存服务Ehcache方案
    sql的一点总结<一>
    消息队列-ActiveMQ
    Kettle数据抽取解决方案
    在VMware上安装VMTools
    数组去重方法
    横向tab计算滚动位置
    无高度内容垂直居中
    常见富文本处理方法
    极简触感反馈Button组件
  • 原文地址:https://www.cnblogs.com/aoligei/p/15010889.html
Copyright © 2011-2022 走看看