当前位置: 首页 > 知识库问答 >
问题:

GetOrCreateCache(cfg)在使用自定义缓存配置创建缓存时引发NullPointerException

应和悦
2023-03-14

我有一个测试套件,试图用IgniteCache替换ConcurrentHashMap DS。 我用相同的数据结构创建了一个IgniteCache和一个CacheConfiguration,我希望我的新IgniteCache是这样的。在运行时,它从开始到停止。在调试中,它表明在iGnite.GetOrCreateCache(cfg)上;步骤它抛出NullPointerException ;

Notes: 
1. I need to run this in embedded mode only without any external installations or external start stop service.
2. Added Ignite start and stop in spring lifecycle events of startup() and shutdown() functions. 
3. I have added the entries in maven dependency and tested the sample run. 
4. It asks for is IGNITE_HOME set? not sure where and what to do if I only want it in embedded mode 
5. Default XML file not found on output screen. I added a sample xml file with configuration and imported it into my main sprint-integration.xml file. 
        public class HarnessCache {

            Ignite ignite;
            private IgniteCache<HarnessCacheKey, ConcurrentHashMap<HarnessDataGroupKey, Object>> harnessCacheMap;
            private CacheConfiguration<HarnessCacheKey, ConcurrentHashMap<HarnessDataGroupKey, Object>> cfg;
        //  private ConcurrentHashMap<HarnessCacheKey, ConcurrentHashMap<HarnessDataGroupKey, Object>> _harnessCacheMap;


            private ConcurrentHashMap<String, List<OutMessageDto>> harnessOutMessageMap;

            public void startup() {
        //      Ignition.start("/mte-testharness/src/main/resources/spring-Ignite-cache-load.xml");
                Ignition.start();
                System.out.println("Test Harness Cache startup....");
                cfg = new CacheConfiguration<>();
                harnessCacheMap = ignite.getOrCreateCache(cfg);
                harnessOutMessageMap = new ConcurrentHashMap<String, List<OutMessageDto>>();
                System.out.println("Test Harness Cache ready....");
            }

            public void shutdown() {
                System.out.println("Test Harness Cache shutting down....");
                harnessCacheMap.clear();
                harnessOutMessageMap.clear();
                ignite.close();
            }
    }

Output console: 
[14:05:25] Configured failure handler: [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0]]
[14:05:25] Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides. 
[14:05:25] Security status [authentication=off, tls/ssl=off] 
[14:05:28] Performance suggestions for grid  (fix if possible) 
[14:05:28] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true 
[14:05:28]   ^-- Enable G1 Garbage Collector (add '-XX:+UseG1GC' to JVM options) 
[14:05:28]   ^-- Specify JVM heap max size (add '-Xmx<size>[g|G|m|M|k|K]' to JVM options) 
[14:05:28]   ^-- Set max direct memory size if getting 'OOME: Direct buffer memory' (add '-XX:MaxDirectMemorySize=<size>[g|G|m|M|k|K]' to JVM options) 
[14:05:28]   ^-- Disable processing of calls to System.gc() (add '-XX:+DisableExplicitGC' to JVM options) 
[14:05:28]   ^-- Disable assertions (remove '-ea' from JVM options) 
[14:05:28] Refer to this page for more performance suggestions: https://apacheignite.readme.io/docs/jvm-and-system-tuning
[14:05:28] 
[14:05:28] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat} 
[14:05:28] 
[14:05:28] Ignite node started OK (id=a9e097dd) 
[14:05:28] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, offheap=3.2GB, heap=3.5GB] 
[14:05:28]   ^-- Node [id=A9E097DD-64E1-4699-9237-65AF0E68D975, clusterState=ACTIVE] 
[14:05:28] Data Regions Configured: 
[14:05:28]   ^-- default [initSize=256.0 MiB, maxSize=3.2 GiB, persistenceEnabled=false] 
Test Harness Cache startup.... 
[14:05:28] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml 
[14:05:29] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml 
[14:05:29] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml 
[14:05:30] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml 
[14:05:30] (wrn) Default Spring XML file not found (is IGNITE_HOME set?): config/default-config.xml 
[14:05:30] Ignite node stopped OK [uptime=00:00:02.341] 

共有1个答案

卫和洽
2023-03-14

它在线抛出NullPointerException

   harnessCacheMap = ignite.getOrCreateCache(cfg);

因为变量ignite中没有任何设置,所以它等于NULL。如果要使用此变量,应将其设置为:

ignite = Ignition.start();
 类似资料:
  • 自定义缓存类使用说明 phpGrace 1.2.1 版本新增了自定义缓存类的功能,您可以将某个相同类型的缓存封装为一个类文件,便于项目的复用 (: 实现步骤 在 phpGrace/caches/ 文件夹下创建您的自定义缓存类文件 文件命名规则 : 缓存类名称.php 类命名规则 : class 缓存类名称 extends \cacheBase{} 使用命名空间 : namespace phpG

  • 自定义state缓存 TIP starter 内置了2种缓存实现 一种是上一节演示的默认实现 另一种是用户自定义的扩展实现。 本节将会使用JustAuth-demo (opens new window)进行演示扩展Redis缓存的方式,当然了,你也可以自定义实现你自己的缓存。 添加 Redis 依赖 <dependency> <groupId>org.springframework.boo

  • 缓存的配置在configs/cache目录,目前支持三种缓存,文件缓存(FileCache), memcache缓存(MemoCache), redis缓存(RedisCache). 文件缓存的配置在file.config.php, 只有一个参数 "cache_dir", 表示文件缓存的根目录 memcache缓存配置在memo.config.php, 可以添加多个memcache服务器,配置格式

  • 我需要在我的服务中使用多个缓存以实现不同的用途。我正在寻找一种方法来分离它们的配置,如maximumSize和expireAfterWrite。我在部署中使用Spring和Kubernetes。yaml我有这个: 我想创建一个新的缓存,cacheC,它将有不同的配置。 我怎么能那样做?谢谢!

  • 大家好 我尝试在SpringBoot应用程序中使用Hazelcast作为本地缓存,如下教程:https://hazelcast.com/blog/non-stop-client-with-near-cache/ 黑泽尔铸造分级版: 在我的版本中,我没有看到为连接到集群设置最大超时的方法(setClusterConnectTimeoutMillis()): ..如果没有它,它就会掉下来 com.ha

  • 本文将介绍如何使用Apache HTTP Server的缓存功能来加速Web和代理服务,同时避免常见问题和错误配置。 Apache HTTP服务器提供了一系列缓存功能,旨在以各种方式提高服务器的性能。 三态RFC2616 HTTP缓存 及其提供者模块提供智能的HTTP感知缓存。内容本身存储在缓存中,旨在遵守控制内容可缓存性的所有各种HTTP头和选项。针对简单和复杂的缓存配置,可以在其中处理代理内容