6

I have plans to load cache concurrently from multiple threads. The simplest form of this would be:

IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache("ints");
ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
for (int i = 0; i < 20000000; i++) {
    int t = i;
    es.submit(() -> {
         cache.put(t, t);
    });
}

Is it safe to do like that? I read the documentation of the method:

Associates the specified value with the specified key in the cache. If the Cache previously contained a mapping for the key, the old value is replaced by the specified value. (A cache c is said to contain a mapping for a key k if and only if c.containsKey(k) would return true.)

There is no any words about thread-safety. So is it safe to put in IgniteCache concurrently?

St.Antario
  • 26,175
  • 41
  • 130
  • 318

2 Answers2

9

The answer is YES, all Ignite APIs are thread safe and can be used concurrently from multiple threads.

However, doing individual puts is not effective way to do data loading, there are better techniques for this. Please refer to this page for details: https://apacheignite.readme.io/docs/data-loading

Valentin Kulichenko
  • 8,365
  • 1
  • 16
  • 12
2

Yes, all IgniteCache methods are thread-safe, as are most other APIs.

Pavel Tupitsyn
  • 8,393
  • 3
  • 22
  • 44