簡體   English   中英

Hazelcast實例不活躍! 在3.2.1

[英]Hazelcast instance is not active! in 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

**

源代碼

**

獨生子

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

已經在郵件列表上看到了你的帖子。 我有一個快速的外觀,在我看來,像一個競爭條件,代理的部分已經初始化,但其他人不是。 需要深入了解它。 可能你可以在bugtracker中創建一個bug,或者可以創建一個單元測試來讓它一直失敗?

這個bug已經在3.2.2-SNAPSHOT中解決了。 它將在本周或下周開始發布。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM