溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

JVM內(nèi)存級分布式緩存Hazelcast的應用

發(fā)布時間:2021-07-07 13:36:50 來源:億速云 閱讀:530 作者:chen 欄目:大數(shù)據(jù)

本篇內(nèi)容主要講解“JVM內(nèi)存級分布式緩存Hazelcast的應用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“JVM內(nèi)存級分布式緩存Hazelcast的應用”吧!

Hazelcast是一個內(nèi)存分布式計算平臺,用于管理數(shù)據(jù)并并行執(zhí)行執(zhí)行應用程序。

1. 它是用Java編寫的。
2. 與其他一些內(nèi)存數(shù)據(jù)庫(如redis)不同,Hazelcast是多線程的,這意味著可從所有可用的CPU內(nèi)核中受益。
3. 與其他內(nèi)存數(shù)據(jù)網(wǎng)格不同 - 它設計用于分布式環(huán)境。它支持每個群集無限數(shù)量的map和緩存。

根據(jù)基準測試,Hazelcast在獲取數(shù)據(jù)方面比Redis快56%,在設置數(shù)據(jù)方面比Redis快44%。

Hazelcast是一個高度可擴展的數(shù)據(jù)分發(fā)和集群平臺。特性包括:

  1. 提供java.util.{Queue, Set, List, Map}分布式實現(xiàn)。

  2. 提供java.util.concurrency.locks.Lock分布式實現(xiàn)。

  3. 提供java.util.concurrent.ExecutorService分布式實現(xiàn)。

  4. 提供用于一對多關系的分布式MultiMap。

  5. 提供用于發(fā)布/訂閱的分布式Topic(主題)。

  6. 通過JCA與J2EE容器集成和事務支持。

  7. 提供用于安全集群的Socket層加密。

  8. 支持同步和異步持久化。

  9. 通過JMX監(jiān)控和管理集群。

  10. 支持動態(tài)HTTP Session集群。

  11. 利用備份實現(xiàn)動態(tài)分割。

  12. 支持動態(tài)故障恢復。

我們來看一下如何使用Hazelcast

pom

<dependency>   <groupId>com.hazelcast</groupId>   <artifactId>hazelcast-all</artifactId>   <version>3.10.1</version></dependency>

在SpringBoot主程序開啟緩存@EnableCaching

@EnableCaching@EnableFeignClients@EnableDiscoveryClient@EnableTransactionManagement@SpringBootApplicationpublic class ProductproviderApplication {   public static void main(String[] args) {
      ApplicationContext app = SpringApplication.run(ProductproviderApplication.class, args);      SpringBootUtil.setApplicationContext(app);   }

}

配置類

@Configurationpublic class HazelcastConfiguration {@Bean    public Config hazelCastConfig(){
        Config config = new Config();        config.setInstanceName("hazelcast-instance").addMapConfig(new MapConfig().setName("configuration").setMaxSizeConfig(new MaxSizeConfig(200,                        MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE)).setEvictionPolicy(EvictionPolicy.LFU)
                .setTimeToLiveSeconds(-1));        return config;    }
}

還是以昨天的汽車配件分類實體類來說明,此處注意一定要實現(xiàn)序列化接口Serializable

@AllArgsConstructor@NoArgsConstructorpublic class ProviderProductLevel implements Provider,Serializable {@Getter    @Setter    private Long id;    @Getter    @Setter    private String code;    @Getter    @Setter    private String name;    @Getter    @Setter    private Integer sort;    @Getter    @Setter    private Integer level;    @Getter    @Setter    private ProductType productType;    @Getter    @Setter    private String pictureUrl;    @Getter    @Setter    private List<OtherProperty> otherProperties;    @Getter    private List<Provider> productListProviders = new CopyOnWriteArrayList<>();    public ProviderProductLevel(Long id,String code,String name,Integer sort,ProductType productType) {this.id = id;        this.code = code;        this.name = name;        this.sort = sort;        this.level = 1;        this.productType = productType;    }public ProviderProductLevel(Long id,String code,String name,Integer sort,String pictureUrl) {this.id = id;        this.code = code;        this.name = name;        this.sort = sort;        this.level = 2;        this.pictureUrl = pictureUrl;    }@Override    public boolean addProvider(Provider provider) {
        LevelDao levelDao = SpringBootUtil.getBean(LevelDao.class);        if (provider instanceof ProviderProductLevel) {
            levelDao.addLevelToLevel(new ParamLevel(this.id,((ProviderProductLevel)provider).getId()));        }return this.productListProviders.add(provider);    }}

寫一個Controller,其中建立分布式緩存Map,不相關的內(nèi)容不做解釋,只說明分布式緩存內(nèi)容

@Slf4j@RestControllerpublic class LevelController {//創(chuàng)建分布式緩存節(jié)點    private HazelcastInstance instance = Hazelcast.newHazelcastInstance();    @Autowired    private LevelDao levelDao;    //一級分類緩存//    private Map<Long,Provider> cachelevelMap1 = new ConcurrentHashMap<>();    private Map<Long,Provider> cachelevelMap1 = instance.getMap("level1");    /**     * 保存一級汽車配件分類     * @param level     * @return     */    @ProductAnnotation    @SuppressWarnings("unchecked")@Transactional    @PostMapping("/productprovider-anon/savelevel1")public Result<String> saveLevel1(@RequestBody ProviderProductLevel level) {
        ProviderFactory.createProviderProductLevel1(level,true);        if (!cachelevelMap1.containsKey(level.getId())) {cachelevelMap1.put(level.getId(), level);        }return Result.success("保存成功");    }/**     * 保存二級汽車配件分類,并將二級產(chǎn)品分類添加到一級產(chǎn)品分類的子分類     * @param id     * @param level     * @return     */    @SuppressWarnings("unchecked")@Transactional    @PostMapping("/productprovider-anon/savelevel2")public Result<String> saveLevel2(@RequestParam("id") Long id, @RequestBody ProviderProductLevel level) {
        ProviderFactory.createProviderProductLevel2(level,true);        if (cachelevelMap1.containsKey(id)) {//此處必須獲取一級分類對象,再添加二級分類,然后重新放入緩存中            //直接使用cachelevelMap1.get(id).addProvider(level),將無法將            //level添加到CopyOnRightArrayList中            Provider level1 = cachelevelMap1.get(id);            level1.addProvider(level);            cachelevelMap1.put(id,level1);            log.info("緩存獲取" + JSONObject.toJSONString(cachelevelMap1.get(id)));        }else {
            Provider level1 = levelDao.findLevel1(id);            log.info(JSONObject.toJSONString(level1));            level1.addProvider(level);            cachelevelMap1.put(id,level1);        }return Result.success("保存成功");    }@GetMapping("/productprovider-anon/getprovider")public Provider getProvider(@RequestParam("id") Long id) {return cachelevelMap1.get(id);    }
}

我們將端口號設為8106,并啟動該端口的項目,我們可以看到這樣一些日志

2019-07-10 10:19:38.381  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.instance.AddressPicker     : [LOCAL] [dev] [3.10.1] Prefer IPv4 stack is true.
2019-07-10 10:19:38.764  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.instance.AddressPicker     : [LOCAL] [dev] [3.10.1] Picked [192.168.192.15]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5702], bind any local is true
2019-07-10 10:19:38.765  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.system                     : [192.168.192.15]:5702 [dev] [3.10.1] Hazelcast 3.10.1 (20180521 - 66f881d) starting at [192.168.192.15]:5702
2019-07-10 10:19:38.765  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.system                     : [192.168.192.15]:5702 [dev] [3.10.1] Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
2019-07-10 10:19:38.766  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.system                     : [192.168.192.15]:5702 [dev] [3.10.1] Configured Hazelcast Serialization version: 1
2019-07-10 10:19:38.766  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.instance.Node              : [192.168.192.15]:5702 [dev] [3.10.1] A non-empty group password is configured for the Hazelcast member. Starting with Hazelcast version 3.8.2, members with the same group name, but with different group passwords (that do not use authentication) form a cluster. The group password configuration will be removed completely in a future release.
2019-07-10 10:19:38.770  INFO [productprovider,,,] 10216 --- [           main] c.h.s.i.o.impl.BackpressureRegulator     : [192.168.192.15]:5702 [dev] [3.10.1] Backpressure is disabled
2019-07-10 10:19:38.770  INFO [productprovider,,,] 10216 --- [           main] h.s.i.o.i.InboundResponseHandlerSupplier : [192.168.192.15]:5702 [dev] [3.10.1] Running with 2 response threads
2019-07-10 10:19:39.422  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.instance.Node              : [192.168.192.15]:5702 [dev] [3.10.1] Creating MulticastJoiner
2019-07-10 10:19:39.428  INFO [productprovider,,,] 10216 --- [           main] c.h.s.i.o.impl.OperationExecutorImpl     : [192.168.192.15]:5702 [dev] [3.10.1] Starting 8 partition threads and 5 generic threads (1 dedicated for priority tasks)
2019-07-10 10:19:39.430  INFO [productprovider,,,] 10216 --- [           main] c.h.internal.diagnostics.Diagnostics     : [192.168.192.15]:5702 [dev] [3.10.1] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-07-10 10:19:39.430  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.core.LifecycleService      : [192.168.192.15]:5702 [dev] [3.10.1] [192.168.192.15]:5702 is STARTING
2019-07-10 10:19:39.538  INFO [productprovider,,,] 10216 --- [           main] c.h.i.cluster.impl.MulticastJoiner       : [192.168.192.15]:5702 [dev] [3.10.1] Trying to join to discovered node: [192.168.192.15]:5701
2019-07-10 10:19:39.549  INFO [productprovider,,,] 10216 --- [cached.thread-3] com.hazelcast.nio.tcp.TcpIpConnector     : [192.168.192.15]:5702 [dev] [3.10.1] Connecting to /192.168.192.15:5701, timeout: 0, bind-any: true
2019-07-10 10:19:39.558  INFO [productprovider,,,] 10216 --- [thread-Acceptor] com.hazelcast.nio.tcp.TcpIpAcceptor      : [192.168.192.15]:5701 [dev] [3.10.1] Accepting socket connection from /192.168.192.15:4508
2019-07-10 10:19:39.561  INFO [productprovider,,,] 10216 --- [thread-Acceptor] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5701 [dev] [3.10.1] Established socket connection between /192.168.192.15:5701 and /192.168.192.15:4508
2019-07-10 10:19:39.561  INFO [productprovider,,,] 10216 --- [cached.thread-3] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5702 [dev] [3.10.1] Established socket connection between /192.168.192.15:4508 and /192.168.192.15:5701
2019-07-10 10:19:46.571  INFO [productprovider,,,] 10216 --- [ration.thread-0] c.h.internal.cluster.ClusterService      : [192.168.192.15]:5701 [dev] [3.10.1]

Members {size:2, ver:2} [
    Member [192.168.192.15]:5701 - 34da2d53-d8d6-4959-aaf2-bd6cda24f0fa this
    Member [192.168.192.15]:5702 - 70b959c7-ebb5-4226-b343-76e7354cbd94
]

2019-07-10 10:19:46.584  INFO [productprovider,,,] 10216 --- [ration.thread-0] com.hazelcast.system                     : [192.168.192.15]:5702 [dev] [3.10.1] Cluster version set to 3.10
2019-07-10 10:19:46.589  INFO [productprovider,,,] 10216 --- [ration.thread-0] c.h.internal.cluster.ClusterService      : [192.168.192.15]:5702 [dev] [3.10.1]

Members {size:2, ver:2} [
    Member [192.168.192.15]:5701 - 34da2d53-d8d6-4959-aaf2-bd6cda24f0fa
    Member [192.168.192.15]:5702 - 70b959c7-ebb5-4226-b343-76e7354cbd94 this
]

2019-07-10 10:19:47.568  INFO [productprovider,,,] 10216 --- [           main] com.hazelcast.core.LifecycleService      : [192.168.192.15]:5702 [dev] [3.10.1] [192.168.192.15]:5702 is STARTED

說明它打開了一個5702端口的分布式緩存系統(tǒng)

我們將Springboot的端口改成8006,并啟動該端口的相同項目,我們可以在啟動日志中看到

2019-07-10 10:23:16.328  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.instance.AddressPicker     : [LOCAL] [dev] [3.10.1] Prefer IPv4 stack is true.
2019-07-10 10:23:16.687  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.instance.AddressPicker     : [LOCAL] [dev] [3.10.1] Picked [192.168.192.15]:5704, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5704], bind any local is true
2019-07-10 10:23:16.688  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.system                     : [192.168.192.15]:5704 [dev] [3.10.1] Hazelcast 3.10.1 (20180521 - 66f881d) starting at [192.168.192.15]:5704
2019-07-10 10:23:16.689  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.system                     : [192.168.192.15]:5704 [dev] [3.10.1] Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
2019-07-10 10:23:16.689  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.system                     : [192.168.192.15]:5704 [dev] [3.10.1] Configured Hazelcast Serialization version: 1
2019-07-10 10:23:16.689  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.instance.Node              : [192.168.192.15]:5704 [dev] [3.10.1] A non-empty group password is configured for the Hazelcast member. Starting with Hazelcast version 3.8.2, members with the same group name, but with different group passwords (that do not use authentication) form a cluster. The group password configuration will be removed completely in a future release.
2019-07-10 10:23:16.692  INFO [productprovider,,,] 11764 --- [           main] c.h.s.i.o.impl.BackpressureRegulator     : [192.168.192.15]:5704 [dev] [3.10.1] Backpressure is disabled
2019-07-10 10:23:16.692  INFO [productprovider,,,] 11764 --- [           main] h.s.i.o.i.InboundResponseHandlerSupplier : [192.168.192.15]:5704 [dev] [3.10.1] Running with 2 response threads
2019-07-10 10:23:17.310  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.instance.Node              : [192.168.192.15]:5704 [dev] [3.10.1] Creating MulticastJoiner
2019-07-10 10:23:17.315  INFO [productprovider,,,] 11764 --- [           main] c.h.s.i.o.impl.OperationExecutorImpl     : [192.168.192.15]:5704 [dev] [3.10.1] Starting 8 partition threads and 5 generic threads (1 dedicated for priority tasks)
2019-07-10 10:23:17.317  INFO [productprovider,,,] 11764 --- [           main] c.h.internal.diagnostics.Diagnostics     : [192.168.192.15]:5704 [dev] [3.10.1] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2019-07-10 10:23:17.317  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.core.LifecycleService      : [192.168.192.15]:5704 [dev] [3.10.1] [192.168.192.15]:5704 is STARTING
2019-07-10 10:23:17.419  INFO [productprovider,,,] 11764 --- [           main] c.h.i.cluster.impl.MulticastJoiner       : [192.168.192.15]:5704 [dev] [3.10.1] Trying to join to discovered node: [192.168.192.15]:5701
2019-07-10 10:23:17.420  INFO [productprovider,,,] 11764 --- [cached.thread-3] com.hazelcast.nio.tcp.TcpIpConnector     : [192.168.192.15]:5704 [dev] [3.10.1] Connecting to /192.168.192.15:5701, timeout: 0, bind-any: true
2019-07-10 10:23:17.420  INFO [productprovider,,,] 11764 --- [cached.thread-3] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5704 [dev] [3.10.1] Established socket connection between /192.168.192.15:4670 and /192.168.192.15:5701
2019-07-10 10:23:23.427  INFO [productprovider,,,] 11764 --- [ration.thread-2] com.hazelcast.system                     : [192.168.192.15]:5704 [dev] [3.10.1] Cluster version set to 3.10
2019-07-10 10:23:23.429  INFO [productprovider,,,] 11764 --- [ration.thread-2] c.h.internal.cluster.ClusterService      : [192.168.192.15]:5704 [dev] [3.10.1]

Members {size:4, ver:4} [
    Member [192.168.192.15]:5701 - 34da2d53-d8d6-4959-aaf2-bd6cda24f0fa
    Member [192.168.192.15]:5702 - 70b959c7-ebb5-4226-b343-76e7354cbd94
    Member [192.168.192.15]:5703 - 02829ed9-0ddf-4675-ba9e-15c1c03b4a50
    Member [192.168.192.15]:5704 - 6ecd17c1-425c-4be0-8914-827f51fdbf3e this
]

2019-07-10 10:23:23.431  INFO [productprovider,,,] 11764 --- [thread-Acceptor] com.hazelcast.nio.tcp.TcpIpAcceptor      : [192.168.192.15]:5704 [dev] [3.10.1] Accepting socket connection from /192.168.192.15:4674
2019-07-10 10:23:23.432  INFO [productprovider,,,] 11764 --- [thread-Acceptor] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5704 [dev] [3.10.1] Established socket connection between /192.168.192.15:5704 and /192.168.192.15:4674
2019-07-10 10:23:23.436  INFO [productprovider,,,] 11764 --- [ration.thread-0] c.h.internal.cluster.ClusterService      : [192.168.192.15]:5703 [dev] [3.10.1]

Members {size:4, ver:4} [
    Member [192.168.192.15]:5701 - 34da2d53-d8d6-4959-aaf2-bd6cda24f0fa
    Member [192.168.192.15]:5702 - 70b959c7-ebb5-4226-b343-76e7354cbd94
    Member [192.168.192.15]:5703 - 02829ed9-0ddf-4675-ba9e-15c1c03b4a50 this
    Member [192.168.192.15]:5704 - 6ecd17c1-425c-4be0-8914-827f51fdbf3e
]

2019-07-10 10:23:23.437  INFO [productprovider,,,] 11764 --- [cached.thread-1] com.hazelcast.nio.tcp.TcpIpConnector     : [192.168.192.15]:5703 [dev] [3.10.1] Connecting to /192.168.192.15:5704, timeout: 0, bind-any: true
2019-07-10 10:23:23.438  INFO [productprovider,,,] 11764 --- [cached.thread-1] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5703 [dev] [3.10.1] Established socket connection between /192.168.192.15:4675 and /192.168.192.15:5704
2019-07-10 10:23:23.438  INFO [productprovider,,,] 11764 --- [thread-Acceptor] com.hazelcast.nio.tcp.TcpIpAcceptor      : [192.168.192.15]:5704 [dev] [3.10.1] Accepting socket connection from /192.168.192.15:4675
2019-07-10 10:23:23.439  INFO [productprovider,,,] 11764 --- [thread-Acceptor] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5704 [dev] [3.10.1] Established socket connection between /192.168.192.15:5704 and /192.168.192.15:4675
2019-07-10 10:23:23.440  INFO [productprovider,,,] 11764 --- [cached.thread-5] com.hazelcast.nio.tcp.TcpIpConnector     : [192.168.192.15]:5704 [dev] [3.10.1] Connecting to /192.168.192.15:5702, timeout: 0, bind-any: true
2019-07-10 10:23:23.444  INFO [productprovider,,,] 11764 --- [cached.thread-5] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5704 [dev] [3.10.1] Established socket connection between /192.168.192.15:4676 and /192.168.192.15:5702
2019-07-10 10:23:23.444  INFO [productprovider,,,] 11764 --- [cached.thread-2] com.hazelcast.nio.tcp.TcpIpConnector     : [192.168.192.15]:5704 [dev] [3.10.1] Connecting to /192.168.192.15:5703, timeout: 0, bind-any: true
2019-07-10 10:23:23.447  INFO [productprovider,,,] 11764 --- [thread-Acceptor] com.hazelcast.nio.tcp.TcpIpAcceptor      : [192.168.192.15]:5703 [dev] [3.10.1] Accepting socket connection from /192.168.192.15:4677
2019-07-10 10:23:23.447  INFO [productprovider,,,] 11764 --- [cached.thread-2] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5704 [dev] [3.10.1] Established socket connection between /192.168.192.15:4677 and /192.168.192.15:5703
2019-07-10 10:23:23.447  INFO [productprovider,,,] 11764 --- [thread-Acceptor] c.h.nio.tcp.TcpIpConnectionManager       : [192.168.192.15]:5703 [dev] [3.10.1] Established socket connection between /192.168.192.15:5703 and /192.168.192.15:4677
2019-07-10 10:23:24.422  INFO [productprovider,,,] 11764 --- [           main] com.hazelcast.core.LifecycleService      : [192.168.192.15]:5704 [dev] [3.10.1] [192.168.192.15]:5704 is STARTED

我們先在8006端口的進程中添加一個一級配件

JVM內(nèi)存級分布式緩存Hazelcast的應用

2019-07-10 10:23:43.408 DEBUG [productprovider,7c69f637b05303a0,7c69f637b05303a0,false] 11764 --- [nio-8006-exec-1] c.c.p.d.L.saveProviderProductLevel1      : ==>  Preparing: insert into product_level (id,code,name,sort,level,product_type) values (?,?,?,?,?,?)
2019-07-10 10:23:43.431 DEBUG [productprovider,7c69f637b05303a0,7c69f637b05303a0,false] 11764 --- [nio-8006-exec-1] c.c.p.d.L.saveProviderProductLevel1      : ==> Parameters: 2459048597577007931(Long), 10003(String), 汽車項鏈(String), 3(Integer), 1(Integer), 車品(String)
2019-07-10 10:23:43.454 DEBUG [productprovider,7c69f637b05303a0,7c69f637b05303a0,false] 11764 --- [nio-8006-exec-1] c.c.p.d.L.saveProviderProductLevel1      : <==    Updates: 1

然后我們在8106端口進程中添加一個二級汽車配件分類,我們來看一看是否可以獲取一級配件分類的緩存

JVM內(nèi)存級分布式緩存Hazelcast的應用

根據(jù)日志打印

2019-07-10 10:26:02.587 DEBUG [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.d.L.saveProviderProductLevel2      : ==>  Preparing: insert into product_level (id,code,name,sort,level,picture_url) values (?,?,?,?,?,?)
2019-07-10 10:26:02.613 DEBUG [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.d.L.saveProviderProductLevel2      : ==> Parameters: 2459048746827121467(Long), 100201(String), 高級項鏈(String), 1(Integer), 2(Integer), sdfasgfd23dg(String)
2019-07-10 10:26:02.635 DEBUG [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.d.L.saveProviderProductLevel2      : <==    Updates: 1
2019-07-10 10:26:02.664  INFO [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.controller.LevelController         : 緩存獲取{"code":"10003","id":2459069885582410555,"level":1,"name":"汽車項鏈","productListProviders":[{"code":"100201","id":2459069910278472507,"level":2,"name":"高級項鏈","pictureUrl":"sdfasgfd23dg","productListProviders":[],"sort":1}],"productType":"TYPE2","sort":3}
2019-07-10 10:26:02.666 DEBUG [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.dao.LevelDao.addLevelToLevel       : ==>  Preparing: update product_level set parent_id=? where id=?
2019-07-10 10:26:02.666 DEBUG [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.dao.LevelDao.addLevelToLevel       : ==> Parameters: 2459048597577007931(Long), 2459048746827121467(Long)
2019-07-10 10:26:02.689 DEBUG [productprovider,deca9b0c23fc065f,deca9b0c23fc065f,false] 10216 --- [nio-8106-exec-1] c.c.p.dao.LevelDao.addLevelToLevel       : <==    Updates: 1

如果此處一級配件是從數(shù)據(jù)庫中查出來的,那么此處的日志將不會有緩存獲取4個字,說明該緩存已經(jīng)同步到了不同進程中。

到此,相信大家對“JVM內(nèi)存級分布式緩存Hazelcast的應用”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關內(nèi)容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI