当前位置: 首页 > news >正文

权威迷失传奇新开网站手机适配网站

权威迷失传奇新开网站,手机适配网站,shopping跨境电商平台,网络营销的基本流程hazelcast入门教程这是解释如何使用Hazelcast的系列文章的续篇。 如果一个人没有阅读其他六个帖子#xff0c;请转到目录并阅读其他帖子。 不同的地图种类 Hazelcast的MultiMap打破了以前使用java.util.Collection接口的常规方式。 实际上#xff0c;我认为MultiMap的概念完… hazelcast入门教程 这是解释如何使用Hazelcast的系列文章的续篇。 如果一个人没有阅读其他六个帖子请转到目录并阅读其他帖子。 不同的地图种类 Hazelcast的MultiMap打破了以前使用java.util.Collection接口的常规方式。 实际上我认为MultiMap的概念完全打破了地图的概念。 虽然法线贴图将一个键关联到一个值但是MultiMaps可以将多个值映射到同一键 。 这是一个非常重要的概念同一键有多个值。 值可以存储在两个不同的集合集合或列表中。 这些集合的行为类似于java.util.Collections库的集合。 安全吗 MultiMap有一种疯狂的方法。 在法线映射中每个键可以存储多个值但是必须手动完成。 这意味着将集合从存储中取出进行任何更改然后将集合放回存储中。 对于线程安全而言这可能是个问题因为先前的步骤需要原子完成否则其他线程可能会读取陈旧或不一致的数据。 MultiMaps通过提供以下服务来帮助解决此问题 可以通过一个put操作添加一个值。 一个人可以用钥匙锁定一个条目。 这是关键双关语因为这意味着开发人员不必跟踪每个条目的单独锁。 例 这个示例有些不同因为在运行示例时我使用Maven的failsafe插件作为主要引擎。 是的我写了两个示例因为我想展示使用MultiMap的两种不同方式。 一种方法是每个线程都拥有自己的游乐场被分配一个唯一的密钥或者被分配一个共享的游乐场或者所有线程共享相同的密钥。 这也是如何将Hazelcast的IdGenerator用作在应用程序中创建线程安全性的方法的示例。 Pom文件 请记住此示例代码利用了Apache的Failsafe Maven插件 。 故障安全插件通过在第一次失败时不终止构建来帮助进行自动集成测试。 它是surefire插件的分支。 我也一直在尝试使用Maven提供的报告。 在命令行中输入“ mvn site”它将生成一个网站。 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0groupIdcom.darylmathisonartifactIdhazelcast-multimap-exampleversion1.0-SNAPSHOTdescriptionExamples of using Hazelcast MultimapdevelopersdevelopernameDaryl Mathisoniddmathisonrolesroledeveloperscmconnectionscm:git:https://github.com/darylmathison/hazelcast-multimap-example.giturlhttps://github.com/darylmathison/hazelcast-multimap-examplepropertiesmaven.compiler.source1.8maven.compiler.target1.8project.build.sourceEncodingUTF-8dependenciesdependencygroupIdcom.hazelcastartifactIdhazelcastversion3.4.2dependencygroupIdjunitartifactIdjunitversion4.12scopetestbuildpluginsplugingroupIdorg.apache.maven.pluginsartifactIdmaven-failsafe-pluginversion2.18.1executionsexecutiongoalsgoalintegration-testgoalverifyreportingpluginsplugingroupIdorg.apache.maven.pluginsartifactIdmaven-project-info-reports-pluginversion2.7reportSetsreportSetreportsreportdependenciesreportindexreportproject-teamreportscmplugingroupIdorg.apache.maven.pluginsartifactIdmaven-javadoc-pluginversion2.10.3reportSetsreportSetreportsreportjavadocreporttest-javadocplugingroupIdorg.apache.maven.pluginsartifactIdmaven-surefire-report-pluginversion2.18.1plugingroupIdorg.apache.maven.pluginsartifactIdmaven-jxr-pluginversion2.5configurationlinkJavadoctruereportSetsreportSetreportsreportjxrreporttest-jxrMultimapAccessThread 这是每个访问类型线程的基类。 package com.darylmathison.multimap;import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastInstanceAware; import com.hazelcast.core.MultiMap;import java.io.Serializable; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock;/*** Abstract class to access MultiMap.*/ public abstract class MultiMapAccessThread implements Serializable, Runnable, HazelcastInstanceAware {protected com.hazelcast.core.HazelcastInstance instance;protected MultiMapLong, Long map;protected String mapName;protected Lock l new ReentrantLock();public void setHazelcastInstance(HazelcastInstance instance) {l.lock();try {this.instance instance;if (mapName ! null !mapName.isEmpty()) {map instance.getMultiMap(mapName);}} finally {l.unlock();}}public String getMapName() {return mapName;}public void setMapName(String mapName) {l.lock();try {this.mapName mapName;} finally {l.unlock();}} } IdMultiMapAccessThread package com.darylmathison.multimap;/*** This thread accesses only one slot in a multimap.*/ public class IdMultiMapAccessThread extends MultiMapAccessThread {private Long id;Overridepublic void run() {l.lock();boolean shouldRun (map ! null id ! null);l.unlock();if(shouldRun) {for (long i 0; i 10; i) {map.put(id, i);}}}public Long getId() {return id;}public void setId(Long id) {this.id id;} } GroupMultiMapAccessThread package com.darylmathison.multimap;/*** Thread designed to share the same slot on a MultiMap.*/ public class GroupMultiMapAccessThread extends MultiMapAccessThread {private static final long MAX 10;private Long groupId;/*** When an object implementing interface Runnable is used* to create a thread, starting the thread causes the objects* run method to be called in that separately executing* thread.** The general contract of the method run is that it may* take any action whatsoever.** see Thread#run()*/Overridepublic void run() {l.lock();boolean shouldRun (groupId ! null map ! null);l.unlock();if(shouldRun) {map.lock(groupId);try {if (map.get(groupId).isEmpty()) {System.out.println(adding to list);for (long i 0; i MAX; i) {map.put(groupId, i);}} else {System.out.println(nothing to add);}} finally {map.unlock(groupId);}}}public void setGroupId(Long groupId) {l.lock();this.groupId groupId;l.unlock();} } HazelcastInstanceResource 此规则启动并关闭运行线程所需的Hazelcast实例。 package com.darylmathison.multimap.test.rule;import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IExecutorService; import org.junit.rules.ExternalResource;/*** Created by Daryl on 4/27/2015.*/ public class HazelcastInstanceResource extends ExternalResource {public static final String SERVICE_NAME Charlotte;HazelcastInstance instance;IExecutorService service;Overrideprotected void before() throws Throwable {super.before();instance Hazelcast.newHazelcastInstance();service instance.getExecutorService(SERVICE_NAME);}Overrideprotected void after() {super.after();service.shutdown();instance.shutdown();}public HazelcastInstance getInstance() {return instance;}public IExecutorService getService() {return service;} } IdMultiMapAccessIT 这是一个使用IdGenerator为线程放置数据的新“操场”或键的示例。 package com.darylmathison.multimap;import com.darylmathison.multimap.test.rule.HazelcastInstanceResource; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.IExecutorService; import com.hazelcast.core.IdGenerator; import org.junit.ClassRule; import org.junit.Test;import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future;/*** Integration test for IdMultiMapAccessThread*/ public class IdMultiMapAccessThreadIT {public static final String MAP_NAME idAccessMap;public static final String GEN_NAME singleAccess;public static final int NUM_THREADS 10;ClassRulepublic static HazelcastInstanceResource hazelcastInstanceResource new HazelcastInstanceResource();Testpublic void testIdThreads() {List threads generateThreads(hazelcastInstanceResource.getInstance());ListFuture? futures new ArrayList(NUM_THREADS);IExecutorService spinner hazelcastInstanceResource.getService();for(IdMultiMapAccessThread thread: threads) {futures.add(spinner.submit(thread));}for(Future? future: futures) {try {future.get();} catch (InterruptedException | ExecutionException e) {e.printStackTrace();}}}private List generateThreads(HazelcastInstance instance) {IdGenerator gen instance.getIdGenerator(GEN_NAME);List threads new ArrayList(NUM_THREADS);for(int i 0; i NUM_THREADS; i) {IdMultiMapAccessThread thread new IdMultiMapAccessThread();thread.setMapName(MAP_NAME);thread.setId(gen.newId());threads.add(thread);}return threads;} } GroupMultiMapAccessThreadIT 这是使用IdGenerator创建共享游乐场或插槽的示例。 package com.darylmathison.multimap;import com.darylmathison.multimap.test.rule.HazelcastInstanceResource; import com.hazelcast.core.IExecutorService; import com.hazelcast.core.IdGenerator; import org.junit.ClassRule; import org.junit.Test;import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future;/*** GroupMultiMapAccessThread Integration Test*/ public class GroupMultiMapAccessThreadIT {public static final int NUM_THREADS 10;public static final String GEN_NAME groupIdGenerator;public static final String MAP_NAME groupMap;ClassRulepublic static HazelcastInstanceResource hazelcastInstanceResource new HazelcastInstanceResource();Testpublic void testGroupMultiMapAccessThread() {List threads createThreads();IExecutorService service hazelcastInstanceResource.getService();ListFuture? futures new ArrayList(NUM_THREADS);for(GroupMultiMapAccessThread thread: threads) {futures.add(service.submit(thread));}for(Future? future: futures) {try {future.get();} catch (InterruptedException | ExecutionException e) {e.printStackTrace();}}}private List createThreads() {List ret new ArrayList(NUM_THREADS);IdGenerator gen hazelcastInstanceResource.getInstance().getIdGenerator(GEN_NAME);Long groupId gen.newId();for(int i 0; i NUM_THREADS; i) {GroupMultiMapAccessThread thread new GroupMultiMapAccessThread();thread.setMapName(MAP_NAME);thread.setGroupId(groupId);ret.add(thread);}return ret;} }结论 在这篇文章中对Hazelcast的MultiMap进行了分析。 结果表明MultiMaps可以为给定键存储多个值。 还显示了线程如何使用IdGenerator作为可能的密钥生成器来共享MultiMap中的数据或如何为其自身存储数据。 该代码可以在GitHub上找到 。 参考资料 http://www.hazelcast.com http://www.hazelcast.org https://github.com/hazelcast/hazelcast 翻译自: https://www.javacodegeeks.com/2015/04/beginners-guide-to-hazelcast-part-7.htmlhazelcast入门教程
http://www.zqtcl.cn/news/29634/

相关文章:

  • 兰溪市住房和城乡建设局网站wordpress注册跳转
  • 甘南网站建设公司优化seo搜索排名
  • 潍坊建设公司网站做网站有兼职吗
  • 无锡网站排名公司app下载应用
  • 网站建设 坚持实用原则拼团系统开发
  • 网站开发技术可以做什么工作国外做电商平台的网站有什么
  • 中小企业建站国外做电商平台的网站还有什么
  • 福建网站建设推广上海建筑设计公司平台
  • 免费域名网站建设产品广告视频制作
  • 南昌网站建设策划网站建设与维护属于什么岗位
  • 深圳公司网站推广免费网页游戏大全
  • 青岛高新区建设局网站企业融资方案
  • 做综合医院网站外贸企业网站改版
  • 哈尔滨大型网站制作给个网站谢谢
  • 网站平台搭建和维护需要什么wordpress 无效的文章类型
  • 做网站有意思吗?成都网站建设多少钱
  • 建设银行北京分行招聘网站做网站的平台有哪些
  • 莱芜网站建设与管理龙岗公司做网站
  • 谷歌生成在线网站地图前端网站开发流程图
  • 网站开发的发展趋势公司网站管理制定的作用
  • 手机网站建设公司排名单页产品销售网站如何做推广
  • 响应式网站建设特色海淀专业企业网站建设
  • 青海省网站建设公司电话订做网站建设
  • 建网站买空间怎样用dede搭建网站
  • 企业网站建立公司wordpress 清空
  • 做推广便宜的网站有哪些搜狗短链接生成
  • 工业设计网站 知乎网络建设费计入哪个科目
  • 建设网站需要什么设施?wordpress 画面做成
  • 松江品划做网站简单网页制作素材图片
  • 深圳公司网站建设哪家好wordpress付费播放器