Java concurrenthashmap由数组声明索引索引

时间:2015-03-06 05:06:04

标签: java multidimensional-array hashmap

我试图生成由数组索引的并发哈希映射。我的应用程序启动了多个线程,这些线程可以将数据存储在由配置文件ID索引的哈希映射中 - >多个线程可以保存到同一个hashmap。为了快速访问,我试图生成一个索引的并发hashmap,如下所示:

public static ConcurrentHashMap<String,Integer> profiledata[] = new ConcurrentHashMap<String,Integer>();

然后当一个线程启动时,它会检查是否设置了该hashmap的索引,如果没有,则设置如下:

try {
        System.out.println(">> Trying profiledata."+profiledata[thisid].isEmpty());
    } catch (NullPointerException e) { 
        System.out.println("profiledata["+thisid+"] not set... initialising");
        profiledata[thisid] = new ConcurrentHashMap<String, String>();
      }

我希望它可以将这样的hashmap声明为thisid是动态的值。

我理解也许我可以将其设置为多维并发hashmap,如果有人可以推荐我如何最好地做到这一点,我真的很感激。

谢谢!

0 个答案:

没有答案