十四、curator recipes之DistributedAtomicLong
简介
和Java的AtomicLong没有太大的不同DistributedAtomicLong旨在分布式场景中维护一个Long类型的数据,你可以像普通单机环境一样来使用它。
官方文档:http://curator.apache.org/curator-recipes/distributed-atomic-long.html
代码示例
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.atomic.AtomicValue;
import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong;
import org.apache.curator.retry.ExponentialBackoffRetry; public class DistributedAtomicLongDemo {
private static CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(3000, 2));
private static String path = "/atomic/long/0001";
private static DistributedAtomicLong atomicLong = new DistributedAtomicLong(client, path, new ExponentialBackoffRetry(1000, 1));
static {
client.start();
} public static void main(String[] args) throws Exception {
System.out.println(atomicLong.get().postValue());
atomicLong.increment();
System.out.println(atomicLong.get().postValue());
atomicLong.decrement();
System.out.println(atomicLong.get().postValue());
AtomicValue<Long> newAtomicLong = atomicLong.compareAndSet(0L, 10L);
System.out.println(newAtomicLong.succeeded());
System.out.println(newAtomicLong.preValue());
System.out.println(newAtomicLong.postValue());
System.out.println(atomicLong.get().postValue());
System.out.println(atomicLong.subtract(5L).postValue());
Thread.sleep(50000);
client.close();
}
}
十四、curator recipes之DistributedAtomicLong的更多相关文章
- 二十、curator recipes之NodeCache
简介 Curator的NodeCache允许你监听一个节点,当节点数据更改或者节点被删除的时候将会触发监听. 官方文档:http://curator.apache.org/curator-recipe ...
- 十、curator recipes之信号量InterProcessSemaphoreV2
简介 跟Java并信号量没有什么不同,curator实现的信号量也是基于令牌桶算法,当一个线程要执行的时候就去桶里面获取令牌,如果有足够的令牌那么我就执行如果没有那么我就阻塞,当线程执行完毕也要将令牌 ...
- 我的MYSQL学习心得(十四) 备份和恢复
我的MYSQL学习心得(十四) 备份和恢复 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) ...
- 雅虎(yahoo)前端优化十四条军规
第一条.尽可能的减少 HTTP 的请求数 (Make Fewer HTTP Requests ) http请求是要开销的,想办法减少请求数自然可以提高网页速度.常用的方法,合并css,js(将一个页面 ...
- Bootstrap<基础二十四> 缩略图
Bootstrap 缩略图.大多数站点都需要在网格中布局图像.视频.文本等.Bootstrap 通过缩略图为此提供了一种简便的方式.使用 Bootstrap 创建缩略图的步骤如下: 在图像周围添加带有 ...
- Bootstrap<基础十四> 按钮下拉菜单
使用 Bootstrap class 向按钮添加下拉菜单.如需向按钮添加下拉菜单,只需要简单地在在一个 .btn-group 中放置按钮和下拉菜单即可.也可以使用 <span class=&qu ...
- AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel
Carousel指令是用于图片轮播的控件,引入ngTouch模块后可以在移动端使用滑动的方式使用轮播控件. <!DOCTYPE html> <html ng-app="ui ...
- C#编程总结(十四)dynamic
http://www.cnblogs.com/yank/p/4177619.html C#编程总结(十四)dynamic 介绍 Visual C# 2010 引入了一个新类型 dynamic. 该类型 ...
- 解剖SQLSERVER 第十四篇 Vardecimals 存储格式揭秘(译)
解剖SQLSERVER 第十四篇 Vardecimals 存储格式揭秘(译) http://improve.dk/how-are-vardecimals-stored/ 在这篇文章,我将深入研究 ...
随机推荐
- NOI2019省选模拟赛 第六场
传送门 又炸了-- \(A\) 唐时月夜 不知道改了什么东西之后就\(A\)掉了\(.jpg\) 首先,题目保证"如果一片子水域曾经被操作过,那么在之后的施法中,这片子水域也一定会被操作&q ...
- 使用git提交代码流程
一.拉取最新代码 一般在本地进行开发时,都是切换到自己的dev分支进行开发,当开发完成需要进行代码提交,在进行代码提交前需要先进行拉取远程仓库代码,进行更新,但是此时会提示需要将本地代码进行commi ...
- HI~
我是一只来自青岛某鶸校的蒟蒻,很高兴能认识各位,本人水平有限,文章中的不足之处,希望大家不吝赐教 我的邮箱是zhenshiluosuo@gmail.com 微信clearsummerday 联系时烦请 ...
- PHP中count()和sizeof()
php中获取数组长度函数有两个count()和sizeof(),如果传递给这个函数的数组是一个空数组,或者是一个没有经过设定的变量,返回的数组元素个数就是0.两函数功能一样,手册上讲,sizeof() ...
- 把 Reative Native 47 版本集成到已有的 Native iOS 工程中
一.搭建开发环境 http://reactnative.cn/docs/0.46/getting-started.html#content 二.创建一个模板 运行以下命令,创建一个最新版本的 reac ...
- HDU-1087-Super Jumping! Jumping! Jumping!(线性DP, 最大上升子列和)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- jquery text html width heigth的用法
<body> <div id="div1"> <h3>我是标题</h3> </div> <div id=" ...
- [Alpha]Scrum Meeting#7
github 本次会议项目由PM召开,时间为4月9日晚上10点30分 时长15分钟 任务表格 人员 昨日工作 下一步工作 木鬼 整理并发布之前因为清明耽误的博客 撰写每日例会报告 SiMrua 添加暂 ...
- ftpClient.retrieveFileStream导致FTPClient的后面操作失败
问题代码: FTPFile[] fs = ftpClient.listFiles(); for (FTPFile ff : fs) { if (ff.getName().equals(fileName ...
- css变量的应用
微软在2017年3月份宣布 Edge 浏览器将支持 CSS 变量,到现在已经过去一年多了,哈哈,是不是有点后知后觉? 这个知识点是在阮一峰的日志上浏览到的,在此借用一下了..跟大家分享一下..... ...