读取Redis的超时例外

时间:2018-05-23 10:43:39

标签: java swing sockets redis socket-timeout-exception

尝试使用Redis使用Java Netbeans构建实时UI,

Jedis jedis = new Jedis("192.168.0.180",6379);
    new Timer (0, new ActionListener() 
  {

        @Override
           public void actionPerformed(ActionEvent e){  

    date = new Date();
    SimpleDateFormat dateFormatter1 = new SimpleDateFormat("d MMMM yyyy  
    hh:mm:ss:SSS");
TimeZone istTimeZone = TimeZone.getTimeZone("Asia/Kolkata");
dateFormatter1.setTimeZone(istTimeZone);
jTextField4.setText (dateFormatter1.format(date));

    try {


    jTextField1.setText(jedis.get("model2"));
    jTextField2.setText(jedis.get("chr2"));
    jTextField3.setText(jedis.get("qr2"));
    if(jedis.get("me2").equals("1")){
    jLabel7.setBackground(Color.GREEN);
    }
     if(jedis.get("me2").equals("0")){
    jLabel7.setBackground(Color.RED);
    }
     if(jedis.get("me2").equals("2")){
    jLabel7.setBackground(Color.WHITE);
    }
     if(jedis.get("eq2").equals("1")){
    jLabel7.setBackground(Color.GREEN);
    }
     if(jedis.get("eq2").equals("0")){
    jLabel7.setBackground(Color.RED);
    }
     if(jedis.get("eq2").equals("2")){
    jLabel7.setBackground(Color.WHITE);
    }

    } catch(Exception ex){
             ex.printStackTrace();
             System.out.println();
    //JOptionPane.showMessageDialog(parent, "Server not connected");
  }
    }
        }).start();
}  

UI持续更新值30分钟,直到套接字超时异常。

 redis.clients.jedis.exceptions.JedisConnectionException: 
 java.net.SocketTimeoutException: Read timed out

at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:201)
at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
at redis.clients.jedis.Protocol.process(Protocol.java:141)
at redis.clients.jedis.Protocol.read(Protocol.java:205)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken 
(Connection.java:297)
at redis.clients.jedis.Connection.getBinaryBulkReply(Connection.java:216)
at redis.clients.jedis.Connection.getBulkReply(Connection.java:205)
at redis.clients.jedis.Jedis.get(Jedis.java:101)
at Asian.AsianView$2.actionPerformed(AsianView.java:235)
at javax.swing.Timer.fireActionPerformed(Timer.java:313)
at javax.swing.Timer$DoPostEvent.run(Timer.java:245)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
atjava.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivil    ege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters 
(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter 
(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy 
(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.net.SocketInputStream.read(SocketInputStream.java:127)
at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:195)

异常后,UI上的字段显示洗牌值 示例:jTextField1.setText(jedis.get("model2"))显示jedis.get("eq2")

的值

请帮助我理解UI的异常行为,并建议解决异常。

使用的jar文件:jedis-2.8.1

0 个答案:

没有答案