188bet官网2018

因此,相对来说比较方便和容易的方法是调整才参数,之后花费较长的时间收集结果。请参考前一篇文章中提到的监控方法成为JavaGC专家PartII—如何监控Java垃圾回收机制。RetryPolicyretryPolicy=newExponentialBackoffRetry(1000,3)CuratorFrameworkclient=CuratorFrameworkFactory.newClient(zookeeperConnectionString,retryPolicy);client.start();Curator已经封装了一些常用的RecipesDistributedLockInterProcessMutexlock=newInterProcessMutex(client,lockPath);if(lock.acquire(maxWait,waitUnit))?{??try??{????//dosomeworkinsideofthecriticalsectionhere??}??finally??{????lock.release();??}}LeaderElectionLeaderSelectorListenerlistener=newLeaderSelectorListenerAdapter(){??publicvoidtakeLeadership(CuratorFrameworkclient)throwsException??{????//thiscallbackwillgetcalledwhenyouaretheleader????//dowhateverleaderworkyouneedtoandonlyexit????//thismethodwhenyouwanttorelinquishleadership??}}?LeaderSelectorselector=newLeaderSelector(client,path,listener);selector.autoRequeue();?//notrequired,butthisisbehaviorthatyouwillprobablyexpectselector.start();参考:http://zookeeper.apache.org/doc/trunk/recipes.htmlhttp://curator.apache.org/curator-recipes/index.html看完本文有收获?请转发分享给更多人关注「ImportNew」,看技术干货(点击上方公众号,可快速关注)来源:阿凡卢,www.cnblogs.com/luxiaoxun/p/4889764.html如有好文章投稿,请点击→这里了解详情Zookeeper统一操作ZooKeeperOperation接口:publicinterfaceZooKeeperOperation{?????/**???*Performstheoperation-whichmaybeinvolvedmultipletimesiftheconnection???*toZooKeeperclosesduringthisoperation???*???*@returntheresultoftheoperationornull???*@throwsKeeperException???*@throwsInterruptedException???*/??publicbooleanexecute()throwsKeeperException,InterruptedException;}因为Zookeeper的操作会失败,这个类封装了多次尝试:/**?*?*LicensedtotheApacheSoftwareFoundation(ASF)underoneormore?*contributorlicenseagreements.?SeetheNOTICEfiledistributedwith?*thisworkforadditionalinformationregardingcopyrightownership.?*TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0?*(the"License");youmaynotusethisfileexceptincompliancewith?*theLicense.?YoumayobtainacopyoftheLicenseat?*?*http://www.apache.org/licenses/LICENSE-2.0?*?*Unlessrequiredbyapplicablelaworagreedtoinwriting,software?*distributedundertheLicenseisdistributedonan"ASIS"BASIS,?*WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.?*SeetheLicenseforthespecificlanguagegoverningpermissionsand?*limitationsundertheLicense.?*/packageorg.apache.zookeeper.recipes.lock;?importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.apache.zookeeper.CreateMode;importorg.apache.zookeeper.KeeperException;importorg.apache.zookeeper.ZooDefs;importorg.apache.zookeeper.ZooKeeper;importorg.apache.zookeeper.data.ACL;importorg.apache.zookeeper.data.Stat;importorg.apache.zookeeper.recipes.lock.ZooKeeperOperation;?importjava.util.List;importjava.util.concurrent.atomic.AtomicBoolean;?/**?*Abaseclassforprotocolimplementationswhichprovidesanumberofhigher??*levelhelpermethodsforworkingwithZooKeeperalongwithretryingsynchronous?*?operationsiftheconnectiontoZooKeeperclosessuchas??*?{@link#retryOperation(ZooKeeperOperation)}?*?*/classProtocolSupport{??privatestaticfinalLoggerLOG=LoggerFactory.getLogger(ProtocolSupport.class);???protectedfinalZooKeeperzookeeper;??privateAtomicBooleanclosed=newAtomicBoolean(false);??privatelongretryDelay=500L;??privateintretryCount=10;??privateListacl=ZooDefs.Ids.OPEN_ACL_UNSAFE;???publicProtocolSupport(ZooKeeperzookeeper){????this.zookeeper=zookeeper;??}???/**???*ClosesthisstrategyandreleasesanyZooKeeperresources;butkeepsthe???*?ZooKeeperinstanceopen???*/??publicvoidclose(){????if(closed.compareAndSet(false,true)){??????doClose();????}??}?????/**???*returnzookeeperclientinstance???*@returnzookeeperclientinstance???*/??publicZooKeepergetZookeeper(){????returnzookeeper;??}???/**???*returntheaclitsusing???*@returntheacl.???*/??publicListgetAcl(){????returnacl;??}???/**???*settheacl????*@paramacltheacltosetto???*/??publicvoidsetAcl(Listacl){????this.acl=acl;??}???/**???*gettheretrydelayinmilliseconds???*@returntheretrydelay???*/??publiclonggetRetryDelay(){????returnretryDelay;??}???/**???*Setsthetimewaitedbetweenretrydelays???*@paramretryDelaytheretrydelay???*/??publicvoidsetRetryDelay(longretryDelay){????this.retryDelay=retryDelay;??}???/**???*Allowderivedclassestoperform????*somecustomclosingoperationstoreleaseresources???*/??protectedvoiddoClose(){??}????/**???*Performthegivenoperation,retryingiftheconnectionfails???*@returnobject.itneedstobecasttothecallee'sexpected????*returntype.???*/??protectedObjectretryOperation(ZooKeeperOperationoperation)?????throwsKeeperException,InterruptedException{????KeeperExceptionexception=null;????for(inti=0;i??????try{????????returnoperation.execute();??????}catch(KeeperException.SessionExpiredExceptione){????????LOG.warn("Sessionexpiredfor:"+zookeeper+"soreconnectingdueto:"+e,e);????????throwe;??????}catch(KeeperException.ConnectionLossExceptione){????????if(exception==null){??????????exception=e;????????}????????LOG.debug("Attempt"+i+"failedwithconnectionlossso"+????????????"attemptingtoreconnect:"+e,e);????????retryDelay(i);??????}????}????throwexception;??}???/**???*Ensuresthatthegivenpathexistswithnodata,thecurrent???*ACLandnoflags???*@parampath???*/??protectedvoidensurePathExists(Stringpath){????ensureExists(path,null,acl,CreateMode.PERSISTENT);??}???/**???*Ensuresthatthegivenpathexistswiththegivendata,ACLandflags???*@parampath???*@paramacl???*@paramflags???*/??protectedvoidensureExists(finalStringpath,finalbyte[]data,??????finalListacl,finalCreateModeflags){????try{??????retryOperation(newZooKeeperOperation(){????????publicbooleanexecute()throwsKeeperException,InterruptedException{??????????Statstat=zookeeper.exists(path,false);??????????if(stat!=null){????????????returntrue;??????????}??????????zookeeper.create(path,data,acl,flags);??????????returntrue;????????}??????});????}catch(KeeperExceptione){??????LOG.warn("Caught:"+e,e);????}catch(InterruptedExceptione){??????LOG.warn("Caught:"+e,e);????}??}???/**???*Returnstrueifthisprotocolhasbeenclosed???*@returntrueifthisprotocolisclosed???*/??protectedbooleanisClosed(){????returnclosed.get();??}???/**???*Performsaretrydelayifthisisnotthefirstattempt???*@paramattemptCountthenumberoftheattemptsperformedsofar???*/??protectedvoidretryDelay(intattemptCount){????if(attemptCount>0){??????try{????????Thread.sleep(attemptCount*retryDelay);??????}catch(InterruptedExceptione){????????LOG.debug("Failedtosleep:"+e,e);??????}????}??}}这个类是本客户端获取到lock和释放lock的时候触发操作的接口:publicinterfaceLockListener{??/**???*callbackcalledwhenthelock????*isacquired???*/??publicvoidlockAcquired();?????/**???*callbackcalledwhenthelockis????*released.???*/??publicvoidlockReleased();}队列(Queue)分布式队列是通用的数据结构,为了在Zookeeper中实现分布式队列,首先需要指定一个Znode节点作为队列节点(queuenode),各个分布式客户端通过调用create()函数向队列中放入数据,调用create()时节点路径名带”qn-”结尾,并设置顺序(sequence)节点标志。鸿吉生物在快速发展中,主动践行社会责任,积极推广生态环保,净化水质,为农户、基地进行养殖技术培训,并率先开创与校企、科研机构定向培训人才和构建产业孵化基地。

2017-2018学年高考物理 全册专题备考强化训练(打包51套)新人教版

上传时间:2018-02-27 年级: 高三 费用:40E币 | 充值
资源简介