×

jsonarray 是什么 c

JSONObject和JSONArray的区别是什么?如何使用Cruator监听zookeeper事件变化

admin admin 发表于2022-07-06 17:00:39 浏览114 评论0

抢沙发发表评论

JSONObject和JSONArray的区别是什么


区别是JSONObject是一个对象,JSONArray是一个数组。

具体步骤如下:

  1. JSONObject是一个{}包裹起来的一个对象(Object),而JSONArray则是包裹起来的一个数组(Array)。

  2. JSONObjec 有键名,JSONArray没有。

  3. 所以解析的时候JSONObject是JSONObject.getString(“msg“),而JSONArray是JSONArray.getString(5),其中这个数字5是位置。


如何使用Cruator监听zookeeper事件变化


掌握zookeeper事件监听机制,非常重要,可以说是跨入了进阶的门槛,只有掌握了如何监听某个节点或路径,我们才能在节点变化后,做一些我们想做的事,包括:1,配置文件同步2,主从切换3,分布式队列4,分布式锁5,其他散仙,在以前的文章里面有写过使用zookeeper原生的api,监听zk节点变化,那么本篇我们就来看下,如何使用curator来完成监听,代码如下:packagecom.qin.curator.zk;importjavax.sound.midi.Patch;importorg.apache.curator.RetryPolicy;importorg.apache.curator.framework.CuratorFramework;importorg.apache.curator.framework.CuratorFrameworkFactory;importorg.apache.curator.framework.CuratorFrameworkFactory.Builder;importorg.apache.curator.framework.api.CuratorWatcher;importorg.apache.curator.framework.recipes.cache.NodeCache;importorg.apache.curator.framework.recipes.cache.NodeCacheListener;importorg.apache.curator.framework.recipes.cache.PathChildrenCache;importorg.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;importorg.apache.curator.framework.recipes.cache.PathChildrenCacheListener;importorg.apache.curator.retry.ExponentialBackoffRetry;importorg.apache.curator.utils.ZKPaths;importorg.apache.zookeeper.WatchedEvent;/****使用curator监听zookeeper节点*@authorqindongliang***/publicclassCuratorWatch{staticCuratorFrameworkzkclient=null;staticStringnameSpace=“php“;static{Stringzkhost=“192.168.46.22:2181“;//zk的hostRetryPolicyrp=newExponentialBackoffRetry(1000,3);//重试机制Builderbuilder=CuratorFrameworkFactory.builder().connectString(zkhost).connectionTimeoutMs(5000).sessionTimeoutMs(5000).retryPolicy(rp);builder.namespace(nameSpace);CuratorFrameworkzclient=builder.build();zkclient=zclient;zkclient.start();//放在这前面执行zkclient.newNamespaceAwareEnsurePath(nameSpace);}publicstaticvoidmain(Stringargs)throwsException{watch();Thread.sleep(Long.MAX_VALUE);}/****监听节点变化***/publicstaticvoidwatch()throwsException{PathChildrenCachecache=newPathChildrenCache(zkclient,“/zk“,false);cache.start();System.out.println(“监听开始/zk..“);PathChildrenCacheListenerplis=newPathChildrenCacheListener(){@OverridepublicvoidchildEvent(CuratorFrameworkclient,PathChildrenCacheEventevent)throwsException{switch(event.getType()){caseCHILD_ADDED:{System.out.println(“Nodeadded:“+ZKPaths.getNodeFromPath(event.getData().getPath()));break;}caseCHILD_UPDATED:{System.out.println(“Nodechanged:“+ZKPaths.getNodeFromPath(event.getData().getPath()));break;}caseCHILD_REMOVED:{System.out.println(“Noderemoved:“+ZKPaths.getNodeFromPath(event.getData().getPath()));break;}}}};//注册监听cache.getListenable().addListener(plis);}}运行后的控制台打印:18:33:07.722[main]INFOo.a.c.f.imps.CuratorFrameworkImpl-Starting18:33:07.727[main]DEBUGo.a.curator.CuratorZookeeperClient-Starting18:33:07.727[main]DEBUGorg.apache.curator.ConnectionState-Starting18:33:07.727[main]DEBUGorg.apache.curator.ConnectionState-reset18:33:07.734[main]INFOorg.apache.zookeeper.ZooKeeper-Clientenvironment:zookeeper.version=3.4.6-1569965,builton02/20/201409:09GMT18:33:07.734[main]INFOorg.apache.zookeeper.ZooKeeper-Clientenvironment:host.name=QINDONGLIANG.dhgatecn.msf18:33:07.734[main]INFOorg.apache.zookeeper.ZooKeeper-Clientenvironment:java.version=1.7.0_0418:33:07.734[main]INFOorg.apache.zookeeper.ZooKeeper-Clientenvironment:java.vendor=OracleCorporation18:33:07.734[main]INFOorg.apache.zookeeper.ZooKeeper-Clientenvironment:java.home=D:\Java\jdk1.7.0_04\jre18:33:07.734[main]INFOorg.apache.zookeeper.ZooKeeper-Clientenvironment:java.class.path=D:\eclipseworkspace2yw\opzk\bin;D:\eclipseworkspace2yw\opzk\lib\curator-client-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-examples-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-framework-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-recipes-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-test-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-x-discovery-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-x-discovery-server-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\curator-x-rpc-2.6.0.jar;D:\eclipseworkspace2yw\opzk\lib\log4j-1.2.15.jar;D:\eclipseworkspace2yw\opzk\lib\zookeeper-3.4.5.jar;D:\eclipseworkspace2yw\opzk\lib\commons-io-2.1.jar
-c

create table as select 怎么写进并行和nologging


您好,很高兴为您解答。


create table target_table
tablespace d_log_03 
parallel (degree 8) 
nologging 
as select * from source_table ;

    

如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】


希望我的回答对您有所帮助,望采纳!


                                                                                                                             ~ O(∩_∩)O~-是什么