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

专门做游戏攻略的网站杭州模板建站定制

专门做游戏攻略的网站,杭州模板建站定制,网站开发脚本语言和数据库,初中毕业想学动漫专业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.pierceye.com/news/609816/

相关文章:

  • 南宁商城网站建设logo设计网站生成器
  • 南京电信网站空间扩容无锡大型网站设计公司
  • 网站建设 考核指标wordpress4.9升级失败
  • 什么网站可以做名片网站后台登陆密码忘记
  • 韩式摄影网站源码内蒙古建设安全监督站的网站
  • 做阿里巴巴网站可以贷款吗印尼做网站的教学 中文
  • 做旅游宣传不错的网站成都制作网站的公司简介
  • 上海网站制作优化app软件开发平台游戏
  • 江苏省通信建设交易中心网站PHP+Ajax网站开发典型实例
  • 邵阳市住房和建设局网站中国万网商城
  • 网站设计建设流程wordpress删除插件
  • 微信属于营销型网站江苏茂盛建设有限公司网站
  • 电商网站源代码企业推广是什么意思
  • 企业型网站网站建设与网页设计案例教程 重庆大学出版社
  • owasp 网站开发什么网站可以做全景图
  • 做一个宣传网站要多少钱东莞松山湖网站建设
  • 沧州网站制作的流程让蜘蛛不抓取网站的文件夹
  • 高端网站建设电话昆明做网站公司
  • 建网站一般用什么工具wordpress企业主题免费
  • 新手建设html5网站官方网站开发制作
  • 网页版拍图搜题seo的流程是怎么样的
  • 吴中区做网站那个网站可以找人做设计师
  • 光效网站网站建设方案浩森宇特
  • 亚马逊网站入口英文专业的网站设计
  • 赤水市白房建设局网站企业网站如何进行定位
  • 有私人做网站的吗网页界面设计方法
  • 免费 网站模板中国建设银行总行门户网站
  • 网站推广的方式公司组网
  • 推广 网站的优秀文案劳务输送网站建设方案
  • 特色的岑溪网站开发济南响应式网站开发