java – Hazelcast实例不活跃!在3.2.1
作者:互联网
我在hazelcast 3.2.1上设置了两个节点,每个节点包含500 MB的数据.我已经配置了客户端近缓存.
我们创建了一个测试环境,其中有3个线程试图同时访问HazelcastInstance客户端.在这种情况下,只有一个线程成功获取地图实例并能够获得输出.其他两个线程显示以下错误
LOG
May 20, 2014 6:28:53 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.2.1] is STARTING
May 20, 2014 6:28:53 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.2.1] is STARTED
May 20, 2014 6:28:53 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.2.1] is CLIENT_CONNECTED
May 20, 2014 6:28:53 PM com.hazelcast.client.spi.ClientClusterService
INFO:
Members [1] {
Member [122.142.15.132]:5701
}
End
Exception in thread "Thread-2" com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
at com.hazelcast.client.spi.ClientProxy.getContext(ClientProxy.java:66)
at com.hazelcast.client.proxy.ClientMapProxy.initNearCache(ClientMapProxy.java:860)
at com.hazelcast.client.proxy.ClientMapProxy.get(ClientMapProxy.java:138)
at Threadimp.execute(Threadimp.java:54)
at Threadimp.run(Threadimp.java:24)
at java.lang.Thread.run(Thread.java:662)
Exception in thread "Thread-1" com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast instance is not active!
at com.hazelcast.client.spi.ClientProxy.getContext(ClientProxy.java:66)
at com.hazelcast.client.spi.ClientProxy.toData(ClientProxy.java:137)
at com.hazelcast.client.proxy.ClientMapProxy.get(ClientMapProxy.java:140)
at Threadimp.execute(Threadimp.java:54)
at Threadimp.run(Threadimp.java:24)
at java.lang.Thread.run(Thread.java:662)
ID: 3 1400590733685 totaltime 209
**
Source Code
**
独生子
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.InMemoryFormat;
import com.hazelcast.config.NearCacheConfig;
import com.hazelcast.core.HazelcastInstance;
public class cacheSigleton implements Serializable {
private static final long serialVersionUID = 1L;
public static cacheSigleton INSTANCE = null;
private static ClientConfig clientConfig = null;
private static HazelcastInstance cacheClient = null;
private static Set<String> nearcaches = new HashSet<String>(
Arrays.asList("HOLIDAY_DATE_MAP","PARAMETERS_MAP"));
private cacheSigleton() {
if (clientConfig == null || cacheClient == null) {
clientConfig = new ClientConfig();
clientConfig.getGroupConfig().setName("dev")
.setPassword("dev-pass");
Iterator<String> iterator = nearcaches.iterator();
String near = null;
NearCacheConfig nearCacheConfig = null;
while (iterator.hasNext()) {
near = iterator.next();
nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setEvictionPolicy("NONE");
nearCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
clientConfig.addNearCacheConfig(near, nearCacheConfig);
}
cacheClient = HazelcastClient.newHazelcastClient(clientConfig);
}
}
public static cacheSigleton getInstance() {
if(INSTANCE == null){
synchronized(cacheSigleton.class) {
INSTANCE = new cacheSigleton();
}
}
return INSTANCE;
}
public HazelcastInstance getHZInstance(){
return cacheClient;
}
}
线程Impl
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
public class Threadimp implements Runnable{
private HazelcastInstance HZinstance = null;
private int id = 0;
public Threadimp(HazelcastInstance HZinstance, int id) {
this.HZinstance = HZinstance;
this.id = id;
}
public void run(){
execute();
}
public void execute() {
//Keys to retrieve the HZ map values
Set<String> keys = new HashSet<String>(
Arrays.asList(""18-Feb-05AAB","09-Jul-10AAB","24-Aug-07AAB","16-Jan-05AABNM","01-Jan-06AAB","16-Jan-09AAB","20-Feb-05AABNM","20-Feb-09AAB","09-Jan-06AAB","26-Jun-09AAB","31-Jul-08AABMY","25-Oct-12AAB","17-Oct-13AAB","03-Dec-11AAB"));
long begin = System.currentTimeMillis();
IMap<Object, Object> map = this.HZinstance.getMap("HOLIDAY_DATE_MAP");
Iterator<String> iterator = keys.iterator();
String key = null;
Object out = null;
while(iterator.hasNext()){
key = iterator.next();
out = map.get(key);
}
long firstRead = System.currentTimeMillis() - begin;
System.out.println("ID: " + id + " " + begin+ " totaltime " +firstRead);
}
public static void main(String args[]) throws Exception
{
System.out.println("Thread Starts");
cacheSigleton instance = cacheSigleton.getInstance();
HazelcastInstance HZinstance = instance.getHZInstance();
Thread test1 = new Thread(new Threadimp(HZinstance, 1));
Thread test2 = new Thread(new Threadimp(HZinstance, 2));
Thread test3 = new Thread(new Threadimp(HZinstance, 3));
test1.start();
test2.start();
test3.start();
System.out.println("Thread End");
}
}
提前致谢,
Sathish所在
解决方法:
这个bug已经在3.2.2-SNAPSHOT中解决了.它将在本周或下周开始发布.
标签:java,caching,multithreading,hazelcast 来源: https://codeday.me/bug/20190708/1404901.html