Any feedback?
在 2021/10/14 15:03, 38797715 写道:
Hi,
The internal code of CacheEntryProcessor in the attachment has been
executed multiple times. Why?
Is there any simple way to solve this problem?
package com.test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
public class IgniteTestDemo {
public static String TEST_DATA = "TEST_DATA";
public static CacheConfiguration<Long, UserInfoData> cfg1 = new CacheConfiguration<>();
public static IgniteCache<Long, UserInfoData> TEST_CACHE;
private static Ignite ignite = null;
public static void main(String[] args) {
init();
initCache();
TEST_CACHE.put(1L, new UserInfoData());
testInvoke(1L);
}
private static void init() {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setMetricsLogFrequency(0);
cfg.setPeerClassLoadingEnabled(true);
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1"));
spi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(spi);
ignite = Ignition.start(cfg);
}
private static void initCache() {
cfg1.setIndexedTypes(Long.class, UserInfoData.class);
cfg1.setName(TEST_DATA);
TEST_CACHE = ignite.getOrCreateCache(cfg1);
}
public static void testInvoke(long uid) {
System.out.println(" ... pre testInvoke ... ");
TEST_CACHE.invoke(
uid, (entry, arguement) -> {
System.out.println("\n---------------------------------");
UserInfoData value;
value = new UserInfoData();
value.getMap1().put(1, new Object());
value.getMap2().put(1, new ItemClass1());
entry.setValue(value);
return null;
}
);
System.out.println(" ... post testInvoke ... ");
}
static class UserInfoData {
public Map<Integer, Object> getMap1() {
return map1;
}
public void setMap1(Map<Integer, Object> map1) {
this.map1 = map1;
}
private Map<Integer, Object> map1 = new HashMap<>();
public Map<Integer, ItemClass1> getMap2() {
return map2;
}
public void setMap2(Map<Integer, ItemClass1> map2) {
this.map2 = map2;
}
private Map<Integer, ItemClass1> map2 = new HashMap<>();
}
static class ItemClass1 {
}
}