HazelCast 多播工作不一致
HazelCast multiCasting works inconsistently
我正在使用 hazelCast 在 2 个不同的 java 应用程序中仅保存一个整数值。我有 2 java 个应用程序,它们是 运行 个不同的服务器。
HazelCast 连接已成功建立。当我尝试使用以下命令增加值时。
DistributedCounter counter = Hazelcast.getHazelcastInstanceByName("myinstance").getDistributedObject("myservice", "value");
counter.inc();
我正在尝试获取值并在完成 10 个增量操作后查看值 =10。但有时我看到值 8 或 9。有时它有效。
公司方法是:
NodeEngine nodeEngine = getNodeEngine();
IncOperation operation = new IncOperation("value", 1);
int partitionId = nodeEngine.getPartitionService().getPartitionId("value");
InvocationBuilder builder = nodeEngine.getOperationService().createInvocationBuilder("myservice", operation, partitionId);
try {
final Future<Integer> future = builder.invoke();
return true;
}
catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
HazelCast 网络配置设置为多播。我禁用了 tcp/ip。
谁能解释为什么 hazelcast 工作不一致?我该如何克服这种情况?
@OkayAtalay,我看到你创建了自己的服务。如果您查看 Hazelcast 文档 http://docs.hazelcast.org/docs/3.10.2/manual/html-single/index.html#implementing-counterproxy 上的示例,您会看到 inc
操作通过调用 future.get()
等待操作完成。即使您只是返回 true/false,您仍然必须等待操作完成才能发送另一个操作。
PS:Hazelcast 已经有 AtomicInteger
& PN-Counter
分区。在这里手动执行您正在执行的操作的对象。
我正在使用 hazelCast 在 2 个不同的 java 应用程序中仅保存一个整数值。我有 2 java 个应用程序,它们是 运行 个不同的服务器。 HazelCast 连接已成功建立。当我尝试使用以下命令增加值时。
DistributedCounter counter = Hazelcast.getHazelcastInstanceByName("myinstance").getDistributedObject("myservice", "value");
counter.inc();
我正在尝试获取值并在完成 10 个增量操作后查看值 =10。但有时我看到值 8 或 9。有时它有效。 公司方法是:
NodeEngine nodeEngine = getNodeEngine();
IncOperation operation = new IncOperation("value", 1);
int partitionId = nodeEngine.getPartitionService().getPartitionId("value");
InvocationBuilder builder = nodeEngine.getOperationService().createInvocationBuilder("myservice", operation, partitionId);
try {
final Future<Integer> future = builder.invoke();
return true;
}
catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
HazelCast 网络配置设置为多播。我禁用了 tcp/ip。
谁能解释为什么 hazelcast 工作不一致?我该如何克服这种情况?
@OkayAtalay,我看到你创建了自己的服务。如果您查看 Hazelcast 文档 http://docs.hazelcast.org/docs/3.10.2/manual/html-single/index.html#implementing-counterproxy 上的示例,您会看到 inc
操作通过调用 future.get()
等待操作完成。即使您只是返回 true/false,您仍然必须等待操作完成才能发送另一个操作。
PS:Hazelcast 已经有 AtomicInteger
& PN-Counter
分区。在这里手动执行您正在执行的操作的对象。