Curator学习笔记(一)读写锁腾讯云开发者社区

基本涵盖了常用的分布式调度功能。那么这块他们是怎么做的。考虑到好的代码肯定做了很多优化,里边会有很多设计模式。但是作者目前还达不到那种一眼就看出其代码的精髓锁着,因此这块作者还是按照老样子。小了解其大概得轮廓。以后再复习设计模式的时候。再去思考这些能够真正提升自身功力的东西。

publicStringcreatesTheLock(CuratorFrameworkclient,Stringpath,byte[]lockNodeBytes)throwsException{StringourPath;//通过我们注入到springioc中的client操作zk,通过判断是否存在该路径进行加锁if(lockNodeBytes!=null){ourPath=(String)((ACLBackgroundPathAndBytesable)client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)).forPath(path,lockNodeBytes);}else{ourPath=(String)((ACLBackgroundPathAndBytesable)client.create().creatingParentContainersIfNeeded().withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL)).forPath(path);}//拿到路径之后,就返回returnourPath;判断是否拿到锁的根据是这里的maxLeasse,写锁这里为1,读锁为2147483647

在锁释放的这个问题上。我们看到也是通过从lackdata中获取重入的次数,然后进行递减的。因为这个lockdata和线程进行绑定。所以在线程轮转中是没有数据消失的问题的。

publicvoidrelease()throwsException{ThreadcurrentThread=Thread.currentThread();//拿到当前线程的重入数据InterProcessMutex.LockDatalockData=(InterProcessMutex.LockData)this.threadData.get(currentThread);if(lockData==null){thrownewIllegalMonitorStateException("Youdonotownthelock:"+this.basePath);}else{//进行锁的重入次数的释放intnewLockCount=lockData.lockCount.decrementAndGet();if(newLockCount<=0){if(newLockCount<0){thrownewIllegalMonitorStateException("Lockcounthasgonenegativeforlock:"+this.basePath);}else{try{//如果锁被释放完毕。那么就开始真正的释放this.internals.releaseLock(lockData.lockPath);}finally{this.threadData.remove(currentThread);}}}}}锁的释放也很简单,直接删除

finalvoidreleaseLock(StringlockPath)throwsException{this.client.removeWatchers();this.revocable.set((Object)null);this.deleteOurPath(lockPath);}总结:通过分析,curator读写锁是通过对zk节点的存在与否进行判断的从而进行加锁的,对于读锁来说只有在不存在的时候线程才能加锁成功。通过将线程和重入次数的绑定,来实现的锁重入机制。当锁被释放之后,通过删除节点来通知其他线程进行加锁。对于读锁来说,单个线程最大或者的读锁数量也是有限制的。通过序列号的方式与写锁进行区别。读锁这块的详细实现作者还没有想明白,以后想明白了再补上。

THE END
1.英语词汇recipe怎么读,是什么意思,单词翻译读音固定搭配用法英汉双解词典包含38652条英汉词条,基本涵盖了全部常用单词的翻译及用法,是英语学习的有利工具。http://ec.newdu.com/28116.html
2.recipe造句recipe基本释义 recipe 英[?res?pi] 美 [?res?pi] 名词复数: recipes n.秘诀;食谱;药方https://www.hao86.com/zaoju_view_9baff343ac9baff3/
3.pieces是什么意思pieces怎么读中文意思用法pieces pieces是什么意思、pieces怎么读 读音:英['pi:s?z] 美['pi:s?z] pieces 基本解释 n. (尤指一套中的)一件( piece的名词复数 );片;条;部分 v. 凑合( piece的第三人称单数 );凑成;修补;组合资料(以便了解情况) pieces 词性变化https://danci.gjcha.com/pieces.html
4.piece是什么意思piece的中文翻译例句用法every everybody evidences piece是什么意思 piece怎么读 piece在线翻译 piece中文意思 piece的意思 piece的翻译 piece的解释 piece的发音 piece的同义词 piece的反义词 piece的用法与例句 piece的相关词组短语 piece意思是什么 piece怎么翻译 piece的中文翻译 piece的意思翻译 piece在线翻译查询 英汉词典 单词专题 https://danci.gei6.com/piece__j956l1fv.html
5.回忆用英语怎么说在英语中,表达“回忆”的词汇有多种,每种词汇都有其独特的用法和语境。例如,recall,发音为[rɪ'kɔːl],意为回忆或取消,作为动词时,它意味着恢复或回想起某事,例句:I remember her face but I cannot recall where I met her. 我记住了她的面容,但是我想不起在什么https://zhidao.baidu.com/question/2129527676986154707.html
6.在英语中,“记忆”和“记性”是一个词吗?“当我把语文课读了多遍还不能背诵时,老师会让我在课堂上站起来,当众质问到:‘你有记性吗?!’ 记性是记忆的土壤,记忆是这土壤上的生长和延伸。拥有记性和记忆,是我们人类与动物、植物的根本之差别。是我们成长、成熟的第一之需求。” 那么在英语https://mp.weixin.qq.com/s?__biz=MzA5MzI5MTc2OQ==&mid=2652265537&idx=1&sn=9664b03d9561857f8694f6d32633b064&chksm=8ad521c8b219c68ddc428046c61ddc4d4f824b37f18f4e4fe2e40d00f6a1cf2da9ed11161b18&scene=27
7.recipes是什么意思recipes怎么读recipes翻译用法发音词组recipes 听听怎么读 英['res?p?z] 美['res?p?z] 是什么意思 n. 烹饪法( recipe的名词复数 );食谱;方法;秘诀 英英释义 recipe n.directions for making something 同义词:formula 学习怎么用 词组短语 secret recipe秘方;秘密配方 recipe for disaster造成灾难的因素https://www.koolearn.com/dict/wd_122922.html
8.recipes是什么意思,recipes怎么读,recipes翻译为:烹饪法(reciprecipes recipes是什么意思,recipes怎么读语音: 英音['res?p?z] 美音['res?p?z] recipes 基本解释 n.烹饪法( recipe的名词复数 );食谱;方法;秘诀 中文词源 recipes 用法和例句提示:点击例句中的单词,就可以看到词义解释 It 's all there , including a chapter with some appetizing , heart-https://fy.tingclass.net/w/recipes
9.和发音NumericalRecipes1的翻译欧路词典 Numerical Recipes 1 生词本:添加笔记: 有奖纠错 | 划词 词组搭配 英语例句库 用户正在搜索 anglicist,anglicize,Anglify,angling,anglist,Anglistics,Anglo,Anglo-,Anglo American,Anglo-American, 相似单词 3G,401(K),a, 历史记录 生词本http://dict.eudic.net/dicts/en/Numerical%20Recipes%201
10.recipes中文翻译recipes的用法和例句recipes怎么读recipes的词义为:n.烹饪法( recipe的名词复数 );食谱;方法;秘诀;等。了解更多recipes的意思,recipes的近义词,recipes的反义词,recipes怎么读,recipes的音标,recipes发音等相关知识,请关注瑞鸿网英语词典(https://dict.ruihongw.com)。瑞鸿网有专业的英语词典编辑团队,定https://dict.ruihongw.com/recipes
11.阅读理解Therearemillionsofrecipes(菜谱)hiddenintheThere are millions of recipes(菜谱) hidden in the boxes and hearts of grandmother and parents. These family recipes are a special part of our family history. Some of them have been passed down from generation(一代人) to generation. "I realized I couldn't go home every weekend for my momhttps://zujuan.21cnjy.com/question/detail/39242842
12.recipe是什么意思,recipe怎么读,recipe的意思是:食谱;处方;秘诀recipe怎么读,recipe的音标和真人发音 英音['res?p?] 美音[?r?sp?] 音节划分:re-cipe recipe是什么意思,recipe的意思是 n.食谱;处方;秘诀 recipe 变化形式 复数: recipes易混淆的单词: RECIPE 所属分类: CET6TEM4IELTSGRE考研TOEFL 使用频率: 星级词汇: recipe的词源和记忆技巧 rechttps://fanyi.kkabc.com/ci/recipe
13.鸡肉用英语怎么读,落实迅速精选RWR版?GJU86知识U: Unique Flavors - The RWR method incorporates unique flavor combinations that set it apart from traditional chicken recipes. 8: 8-Minute Cooking Time - One of the hallmarks of the RWR version is the rapid cooking time, which is achieved through a combination of high heat and precise timinghttp://www.hbpdxcl.com/post/9457.html
14.论文阅读CVPR2024SURE:SUrveyREcipesforbuildingreliablea联合使用锐度感知最小化(SAM)[19]和随机加权平均(SWA)[35]来增强平坦最小值。 锐度感知最小化(Sharpness-Aware Minimization, SAM) SAM[8,19]是一种优化方法,它通过寻找位于平坦邻域的参数来增强模型泛化,从而使DNN具有一致的小损失。 随机加权平均(SWA) https://blog.csdn.net/2305_76351374/article/details/139498558
15.专题七阅读理解(全国卷)In Save Money: Good Food, she visits a different home each week and with the help of chef Matt Tebbutt offers top tips on how to reduce food waste, while preparing recipes for under £5 per family a day. And the Good Morning Britain presenter says she’s been able to put a lot ofhttps://zujuan.xkw.com/thematiclist/12pt540ct1104n15330.html
16.如何快速读懂英语长难句?英语阅读,是从单词,词语用法,句型,语法的基础之前,进行运用更多的英语阅读技巧方法才能够更多的提高https://www.zhihu.com/question/19750093/answer/980710865?utm_id=0
17.NumericalrecipesinC:theartofscientificcomputingWilliam H. PressBrian P. FlannerySaul A. TeukolskyWilliam T. Vetterling Choice Reviews Online Jun 1993 4607被引用 0笔记 共1个版本 摘要原文 From the Publisher:This is the revised and greatly expanded Second Edition of the hugely popular Numerical Recipes: The Art of Scientific Computing. The prhttps://readpaper.com/paper/2432517183
18.A[英文版]ICouldNoshClassicJewA[英文版] I Could Nosh Classic Jew-ish Recipes Revamped for Every Day 2023 烘焙杂志 2023年美食英国英语 2023年-09月-13日0 条评论161 次阅读 <-- 觉得不错的话,分享给您的朋友吧! 基本介绍: 编号:A0853 语言:英文 格式:EPUB (文字可复制)http://www.yuedubar.com/archives/96394
19.all,Ihadtoreadtherecipes,thenwe'llmakesandwichesFirst of all, I had to read the recipes, then we'll make sandwiches First, I can not but read the recipes carefully, then makes the sandwich again First of all, I have to read carefully and then do 3 recipes, Meiji First of all, I had to read the recipes, then we'll make sandwhttp://zaixian-fanyi.cn/fanyi_259741