redis 使用謹慎, 客戶端會出現髒堵

package com.test.redis; import redis.clients.jedis.Jedis; public class Test { public static void main(String[] args) { final Jedis is = new Jedis("10.****",9999); is.select(1); is.set("1231231", "123123"); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i =0; i < 5; i++){ new Thread(new Ts(i,is)).start();; } System.out.println("ok!"); while(true){ System.out.println("live"); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } class Ts implements Runnable{ int i ; Jedis is ;  public Ts(int i,Jedis is){ this.i  = i; this.is = is; } @Override public void run() { String k = "test"+i; String v = "test"+i; is.set(k, v); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int j =0; j < Integer.MAX_VALUE; j++){ String tl = is.get(k); if(null ==tl){ try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("null"); continue; } if(!v.equals(tl)){ System.out.println(" no equal:"+i+"\t key:"+k+"\t tl:"+tl); //出現了髒堵 System.exit(0);; } System.out.println(i); if(i%10000 ==0){ System.out.println(" me live:"+i); try { Thread.sleep(10); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
相關文章
相關標籤/搜索