hazelcast java_Spring Boot和Hazelcast使用详解
你是否遇到过应用程序性能下降的问题?有没有想过提升spring性能?如果是这样 - 那么这篇文章绝对适合你。在这里,我们将谈论使用超级强大和领先的内存数据网格提高应用程序的性能!
什么是hazelcast?
hazelcast是一个内存分布式计算平台,用于管理数据并并行执行执行应用程序。
1. 它是用java编写的。
2. 与其他一些内存数据库(如redis)不同,hazelcast是多线程的,这意味着可从所有可用的cpu内核中受益。
3. 与其他内存数据网格不同 - 它设计用于分布式环境。它支持每个群集无限数量的map和缓存。
根据基准测试,hazelcast在获取数据方面比redis快56%,在设置数据方面比redis快44%。
hazelcast是一个高度可扩展的数据分发和集群平台。特性包括:
提供java.util.{queue, set, list, map}分布式实现。
提供java.util.concurrency.locks.lock分布式实现。
提供java.util.concurrent.executorservice分布式实现。
提供用于一对多关系的分布式multimap。
提供用于发布/订阅的分布式topic(主题)。
通过jca与j2ee容器集成和事务支持。
提供用于安全集群的socket层加密。
支持同步和异步持久化。
为hibernate提供二级缓存provider 。
通过jmx监控和管理集群。
支持动态http session集群。
利用备份实现动态分割。
支持动态故障恢复。
现在需要将它添加到spring boot项目中并开始使用它的优势。
org.springframework.boot groupid>
spring-boot-starter-parent artifactid>
2.0.0.release version>
parent>
org.springframework.boot groupid>
spring-boot-starter-web artifactid>
dependency>
com.hazelcast groupid>
hazelcast artifactid>
dependency>
com.hazelcast groupid>
hazelcast-spring artifactid>
dependency>
dependencies>
要将hazelcast添加到spring boot应用程序,只需要两个依赖项。下我们需要配置hazelcast实例。有两种方法可以做到这一点:
1. 通过java配置。
2. 通过创建hazelcast.xml配置文件。
我们选择第一个方式:
import com.hazelcast.config.config;
import com.hazelcast.config.evictionpolicy;
import com.hazelcast.config.mapconfig;
import com.hazelcast.config.maxsizeconfig;
import org.springframework.context.annotation.bean;
import org.springframework.context.annotation.configuration;
@configuration
public class hazelcastconfiguration {
@bean
public config hazelcastconfig(){
config config = new config();
config.setinstancename(“hazelcast-instance”)。
addmapconfig(
new mapconfig()。
setname(“configuration”)
.setmaxsizeconfig(新maxsizeconfig(200,maxsizeconfig.maxsizepolicy。free_heap_size))
.setevictionpolicy(evictionpolicy。lru)
.settimetoliveseconds(-1));
return config;
}
}
实例已配置 - 现在我们可以访问hazelcast并使用数据进行操作。
对于这个例子,将创建只有3个映射的hazelcastcontroller:
一个是设置数据;
一种是按ke键查询数据;
一个是从hazelcast获取所有数据;
@restcontroller
@requestmapping("/hazelcast")
public class hazelcastcontroller {
private final logger logger = loggerfactory.getlogger(hazelcastcontroller.class);
private final hazelcastinstance hazelcastinstance;
@autowired
hazelcastcontroller(hazelcastinstance hazelcastinstance) {
this.hazelcastinstance = hazelcastinstance;
}
@postmapping(value = "/write-data")
public string writedatatohazelcast(@requestparam string key, @requestparam string value) {
map hazelcastmap = hazelcastinstance.getmap("my-map");
hazelcastmap.put(key, value);
return "data is stored.";
}
@getmapping(value = "/read-data")
public string readdatafromhazelcast(@requestparam string key) {
map hazelcastmap = hazelcastinstance.getmap("my-map");
return hazelcastmap.get(key);
}
@getmapping(value = "/read-all-data")
public map readalldatafromhazelcast() {
map hazelcastmap = hazelcastinstance.getmap("my-map");
return hazelcastinstance.getmap("my-map");
}
}
在控制器中,我们自动安装了hazelcastinstance - 这是hazelcast库提供的接口。通过使用此实例,我们可以操作内存数据网格中的数据。因此,可以使用postman将一些记录保存到hazelcast中。
重要的是 - 即使从不同的springboot应用程序实例启动,也可以将数据存储在同一个缓存中。比如可以将应用程序端口更改为8081,并运行该应用程序的另一个实例,然后将尝试从之前存储的hazelcast中获取所有数据。
因为hazelcast是集群的,数据可以在许多应用程序实例之间共享。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。
希望与广大网友互动??
点此进行留言吧!
hazelcast java_Spring Boot和Hazelcast使用详解相关推荐
- rabbitmq fanout java_spring boot整合RabbitMQ实例详解(Fanout模式)
1.Fanout Exchange介绍 Fanout Exchange 消息广播的模式,不管路由键或者是路由模式,会把消息发给绑定给它的全部队列,如果配置了routing_key会被忽略. 如上图所示 ...
- Spring Boot的启动器Starter详解
Spring Boot的启动器Starter详解 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs Spring Boot ...
- BOOT客户管理系统(详解)
BOOT客户管理系统(详解) Github:https://github.com/wz20 Gitee:https://gitee.com/Wang-ZeLXM/boot-crm 本文中的代码不可以直 ...
- ElasticSearch——Spring Boot 集成 ES 操作详解
文章目录 ElasticSearch--Spring Boot 集成 ES 操作详解 1.SpringBoot 集成 ES 2.索引的API操作详解 3.文档的API操作详解 ElasticSearc ...
- 轻量级数据库sqlite,spring boot+sqlite的配置详解 (一)
spring boot+sqlite的配置,及成功运行详解 sqlite数据库的安装与调试 首先,通过sqlite官方地址下载对应的安装包 https://www.sqlite.org/downloa ...
- 轻量级数据库sqlite,spring boot+sqlite的配置详解 (二)
轻量级数据库sqlite,spring boot+sqlite的配置详解 (二) 轻量级数据库sqlite,spring boot+sqlite的配置详解 (一) 首先,需要创建一个spring bo ...
- spring boot application.properties 属性详解
2019年3月21日17:09:59 英文原版: https://docs.spring.io/spring-boot/docs/current/reference/html/common-appli ...
- Spring Boot jackson配置使用详解
Spring Boot系列-json框架jackson配置详解 T1 - 前言 目前Java最常见的3中JSON操作框架分别为Gson.Jackson.FastJson,该篇文章主要讲解jackson ...
- Spring Boot的SpringApplication类详解
相信使用过Spring Boot的开发人员,都对Spring Boot的核心模块中提供的SpringApplication类不陌生.SpringApplication类的run()方法往往在Sprin ...
最新文章
- CCControlSwitch 、CCControlSlider、CCControlButton
- getitemdata中参数设置
- DEBUG各命令详细说明(很详细)
- Educational Codeforces Round 64 Div.2 D - 0-1-Tree
- 学习腾讯的hover效果
- 编译OpenJDK12:运行提示缺少freetype
- 第一个Net+Mysql的例子,比想象的简单很多
- ipsec和nat穿越
- 解读SOA平台---概念分析
- leetcode *207. 课程表(拓补排序)(2020.8.4)
- pip缓存下载的包文件
- 计算机pdf转换word,PDF怎么转换成Word?解决PDF转Word的小妙招
- 金融安全资讯精选 2017年第二期:金融网络安全和反欺诈方法论_金融新兴技术成熟度几何?...
- 解决电脑关机状态下按键盘会开机的问题
- 亚马逊Alexa Skill介绍
- Cannot open url. please check this url is correct
- Pycharm中怎么给字典中的多个键-值对同时加上单引号
- 《Clean Code》代码的整洁之道(一)
- 微信录音amr音频文件转mp3格式
- hive安装:3.1.2版本