生成唯一值的思路之一
2016-06-30 17:34
253 查看
public class Sequence { private static final String SEQUENCE_ROOT = "/sequence"; private static final String PREFIX_NODE = "num"; private ZookeeperClient zookeeperClient; public Sequence() { } public String generate() { String time = DateUtils.formatDate(new Date(), DATE_FORMAT.DETAIL.getFormat()); try { String e = (String)((ACLBackgroundPathAndBytesable)this.zookeeperClient.getClient().create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL)).forPath(ZKPaths.makePath("/sequence", time, new String[]{"num"}), new byte[0]); String[] nodes = e.split("/"); String node = nodes[nodes.length - 1]; String suffix = node.substring("num".length()); return time + suffix.substring(suffix.length() - 4); } catch (Exception var6) { var6.printStackTrace(); return null; } } @Autowired public void setZookeeperClient(ZookeeperClient zookeeperClient) { this.zookeeperClient = zookeeperClient; } }
相关文章推荐
- 数据库中identity字段不必是系统产生的唯一值 性能优化方法(新招)
- mysql 获取全局唯一值
- ArcEngine 专题图关键代码
- sql select 返回唯一不同的值
- 删除表中某属性相同的值
- 【C++】找数组中唯一出现两次的数
- 筛选数组中的唯一值
- python查看列的唯一值
- pandas的唯一值、值计数以及成员资格的示例
- python查看列的唯一值方法
- select全选,反选和不选的功能
- 同一界面放两个TTIWDBAdvWebGrid的问题(delphi IW TMS)
- 转屏
- APP开发接口分类介绍
- thinkPHP框架研究
- WebView中调用系统相册或拍照上传
- JAX-RS入门 八: HTTP响应
- Spring Aop配置时的切入点表达式
- 动态规划
- 2.转动的地球shader