我正在使用JBossCache 'Malagueta' 3.2.0.GA
我在生产环境中遇到了奇怪的问题,有时写入 jboss 缓存无法正常工作。我试图用简单的 java 应用程序重现这种情况
public static void testCache() {
Cache cache = new DefaultCacheFactory().createCache(false);
cache.create();
cache.start();
final Node node = cache.getRoot().addChild(Fqn.fromString("/child1"));
int threadsCount = 20;
final CyclicBarrier b = new CyclicBarrier(threadsCount);
for (int i = 0; i < threadsCount; i++) {
final long j = i;
new Thread(new Runnable() {
@Override
public void run() {
try {
b.await();
String name = RandomGenerator.getRandomName(4);
node.put(j, name);
String nameFromCache = (String) node.get(j);
if (!name.equals(nameFromCache)) {
System.out.println("error");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
有时,此测试输出“错误”,我从static void main
失败中运行。3 次运行中的 1 次返回“错误”消息。它只是返回null。我无法在每台机器上重现它。
有什么线索吗?