在hazelcast中存储对象

时间:2016-11-14 05:10:42

标签: hazelcast hazelcast-imap

我正在尝试将我的对象存储在Hazelcast地图中,但它不起作用。它创建了一个新的实例,我可以在控制台和mancenter中看到它。它还创建了地图但内部没有任何内容。此外,System.out.println(accountMap.get())不打印任何内容。 我甚至尝试过使用简单的字符串进行put操作,结果仍然相同。

这是我的代码:

userAccount user = new userAccount();
user.name = "pras";
user.pass = "12345";


HazelcastInstance instance = Hazelcast.newHazelcastInstance (new Config());
                Map<Integer, userAccount> accountMap = instance.getMap("userMap");
                accountMap.put(1, user);
                System.out.println (accountMap.get(1));

1 个答案:

答案 0 :(得分:0)

给定:     包com.hazelcast;

import java.io.Serializable;

public class userAccount implements Serializable {
    String name;
    String pass;
}

从上面你的代码,我得到以下输出:

INFO: [192.168.1.70]:5701 [dev] [3.8.1] 

Members [1] {
    Member [192.168.1.70]:5701 - f8f3cf77-9b02-48b7-8a61-f353c40a6267 this
}

Apr 21, 2017 3:19:28 PM com.hazelcast.core.LifecycleService
INFO: [192.168.1.70]:5701 [dev] [3.8.1] [192.168.1.70]:5701 is STARTED
Apr 21, 2017 3:19:28 PM com.hazelcast.internal.partition.impl.PartitionStateManager
INFO: [192.168.1.70]:5701 [dev] [3.8.1] Initializing cluster partition table arrangement...
com.hazelcast.userAccount@70ab80e3

希望这有帮助