Is the ignition cache thread safe?

I have plans to load cache from multiple threads concurrently. 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);
    });
}

      

Can you do this? I read the documentation for the method:

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

There is no word on thread safety. So is it safe to paste IgniteCache

at the same time?

+3


source to share


2 answers


Answer: YES, all Ignite APIs are thread safe and can be used simultaneously from multiple threads.



However, doing individual puts is not an efficient way to load data; there are better methods for that. See this page for more details: https://apacheignite.readme.io/docs/data-loading

+5


source


Yes, all methods IgniteCache

are thread safe, like most other APIs.



+1


source







All Articles