自己写的在服务器上一段重试次数的程序,对于TAIR操作需要加乐观锁版本号防止集群上数据安全
来源:互联网 发布:linux c mysql编程 编辑:程序博客网 时间:2024/06/07 23:10
封装类
package aa;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;public class TairMethodWrapper {private static Map<String, TairRetryEntry> superdealCache = new ConcurrentHashMap();public static interface SuperdealTairMethodWrapperInvoke {void invoke();}class TairRetryEntry {long writeTime;int count;}public void invoke(SuperdealTairMethodWrapperInvoke superdealTairMethodWrapperInvoke,String type, Long repeatInterval, Integer repeatCount) {// TODO Auto-generated method stubif(!isRetry(type, repeatInterval, repeatCount)) {isRetry(type, repeatInterval, repeatCount);}}protected boolean isRetry(String type, Long repeatInterval,Integer repeatCount) {TairRetryEntry entry = superdealCache.get(type);if (entry == null) {entry = new TairRetryEntry();entry.count = 0;entry.writeTime = System.currentTimeMillis();superdealCache.put(type, entry);} else if ((System.currentTimeMillis() - entry.writeTime) >= repeatInterval) {entry.count = 0;entry.writeTime = System.currentTimeMillis();}entry.count++;if (entry.count >= repeatCount) {return true;}//do our method here if success,return truereturn false;}}
调用方法
import aa.TairMethodWrapper;import aa.TairMethodWrapper.SuperdealTairMethodWrapperInvoke;public class TestRetry1 {public static void main(String[] args) {retry1();}private static void retry1() { new TairMethodWrapper().invoke(new SuperdealTairMethodWrapperInvoke(){@Overridepublic void invoke() {// TODO Auto-generated method stub}}, "featuredeal", Long.parseLong("150"), 5);}}
0 0
- 自己写的在服务器上一段重试次数的程序,对于TAIR操作需要加乐观锁版本号防止集群上数据安全
- 自己写的一段重试代码
- 一段在IE上加按钮的Script,主要操作注册表,先贴了再说
- 如何在自己的服务器上装载上 gitbook 写的书
- 在github上写自己的博客
- 在自己的MAC上搭建服务器
- 在自己的服务器上安装GitBook
- 查看服务器上安装的nginx版本号
- 查看Linux服务器上的Redis版本号
- 在caffe上跑自己的数据
- 在caffe上跑自己的数据
- 在caffe上跑自己的数据
- 在caffe上跑自己的数据
- 在caffe上跑自己的数据
- 在caffe上跑自己的数据
- 在caffe上跑自己的数据
- 在linux服务器上搭建相对安全的FTP服务器
- 在自己电脑上搭建服务器 发布自己的网站
- php ajax 实现三级省市区联动
- 使用FusionCharts ASP Class创建图表
- default.properties导致不能点Android选项问题
- 没有目录建目录,没有文件建文件
- CloudStack安装详细步骤
- 自己写的在服务器上一段重试次数的程序,对于TAIR操作需要加乐观锁版本号防止集群上数据安全
- 异常捕获
- 【Spring学习笔记】控制反转IoC
- 计算机网络笔试题 详细分析复习知识点
- git pull push没有指定branch报错的解决方法
- frameset窗框
- 线程间操作无效: 从不是创建控件“”的线程访问它
- 使用(C++库)istringstream输入(格式化)
- python时间处理函数