2

Trying to build a real time UI using Java Netbeans using Redis,

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();
}  

The UI updates the value continuously fine for 30 min, till the socket time out exception.

 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)

After the exception the fields on the UI displays shuffled values example: jTextField1.setText(jedis.get("model2")) displays the value of jedis.get("eq2")

Please help me with understanding the abnormal behavior of the UI also suggest the solution for exception.

jar file used: jedis-2.8.1

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
sridhar
  • 83
  • 1
  • 10
  • take a look at https://stackoverflow.com/questions/14993644/configure-jedis-timeout you can configure the timeout. – keuleJ May 23 '18 at 11:33
  • By the way, shouldnt you create a new connection every time the Action runs instead of reusing the same over and over? Also, maybe you should add a delay between the runs of the actions by setting the delay to 100 for example – keuleJ May 23 '18 at 11:38
  • i have added a delay of 100 ms which solved the problem of display being shuffled, but i am continuously getting "connection time out" exception followed by "Read time out exception" which is handled by catch – sridhar May 24 '18 at 06:06
  • yes, I think you use the same connection until the connection is timed out. Maybe you should build a new connection on each call? – keuleJ May 24 '18 at 08:30
  • if build a new connection on each call should i close the connection every time?, using "jedis.close()" – sridhar May 24 '18 at 10:25
  • 1
    Yes, try it out and tell here what you experience... – keuleJ May 24 '18 at 10:58

0 Answers0