このコンテンツは選択した言語では利用できません。
7.2.2. Adding and Replacing a Key Value
Red Hat JBoss Data Grid offers a thread-safe data structure.
The following procedure is an example that defines what each line entered into the
DefaultCacheQuickstart.java file does:
Procedure 7.3. Adding and Replacing a Key Value
- Add an entry
keywithvalueas the key's value.cache.put("key", "value");cache.put("key", "value");Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure 7.4. Replacing a Key Value
- The following code searches for keys (named
keyandkey2). If the two specific keys beings searched for are not found, JBoss Data Grid creates two new keys with the specified key names and values.cache.putIfAbsent("key", "newValue"); cache.putIfAbsent("key2", "value2");cache.putIfAbsent("key", "newValue"); cache.putIfAbsent("key2", "value2");Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The following code confirms that the value of the stored key equals the value we wanted to store.
assertEquals(cache.get("key"), "value"); assertEquals(cache.get("key2"), "value2");assertEquals(cache.get("key"), "value"); assertEquals(cache.get("key2"), "value2");Copy to Clipboard Copied! Toggle word wrap Toggle overflow
See Also: