Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8133520

Java Swing Application CPU and Memory Spike Over RDP When Screen Locked

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 7u5
    • client-libs

      FULL PRODUCT VERSION :
      java version " 1.7.0_05 "
      Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 Enterprise SP1 64-bit

      A DESCRIPTION OF THE PROBLEM :
      We use Remote Desktop on a client machine (Windows 7, Java 7u5) in order to connect to a host machine also running Windows 7 and Java 7u5. Once connected, we run a Java swing application and see the GUI. After running this application for ~10 minutes, the application consumed one second of CPU time and had a working set size of ~35MB. We then proceeded to lock the screen on the Remote Desktop connection. After ~10 minutes, we unlocked the machine and the Java application had consumed >8 minutes of CPU time and the working set of memory grew to >117MB. The CPU usage after the screen was unlocked dropped back down to essentialy 0%. This test was run using Java 6u34, Java 7u5, and Java 7u21 and the results were the same in all instances.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Remote Desktop into a machine where the Java application is located.
      2) Start the Java application.
      3) Keep the GUI open on the foreground.
      4) In the remote desktop session, click Start ->Arrow next to " Log Off " -> Lock.
      5) Wait ~10 minutes.
      6) Unlock remote session.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The CPU usage of the Swing application during the screen lock should have been consistent to when the screen was unlocked (~1 CPU second).
      ACTUAL -
      The CPU usage of the Swing application was very high while the screen was locked which could be verified by looking at the CPU time, which was >8 CPU minutes. The process working set also grew abnormally fast during the screen lock.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package rdptest;

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JButton;

      /**
       *
       * @author tongw
       */
      public class RDPTest2 extends javax.swing.JFrame {

          /**
           * Creates new form Frame
           */
          public RDPTest2() {
              initComponents();
          }

          private void go() {
              jButton1.setText( " iteration " );
              
              jButton2.setText( " exit " );
              jButton2.addActionListener(new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                      // do something more graceful
                      System.exit(0);
                  }
              });

              new java.util.Timer().schedule(new java.util.TimerTask() {
                  int iteration = 0;

                  public void run() {
                      java.awt.EventQueue.invokeLater(new Runnable() {
                          public void run() {
                              final JButton button = jButton1;
                              ++iteration;
                              button.setText( " " + iteration);
                          }
                      });
                  }
              }, 1, 1000);
          }

          /**
           * This method is called from within the constructor to initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is always
           * regenerated by the Form Editor.
           */
          @SuppressWarnings( " unchecked " )
          // <editor-fold defaultstate= " collapsed " desc= " Generated Code " >//GEN-BEGIN:initComponents
          private void initComponents() {

              jButton1 = new javax.swing.JButton();
              jButton2 = new javax.swing.JButton();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

              jButton1.setText( " jButton1 " );

              jButton2.setText( " jButton2 " );

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGap(73, 73, 73)
                      .addComponent(jButton1)
                      .addGap(111, 111, 111)
                      .addComponent(jButton2)
                      .addContainerGap(165, Short.MAX_VALUE))
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGap(29, 29, 29)
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(jButton1)
                          .addComponent(jButton2))
                      .addContainerGap(248, Short.MAX_VALUE))
              );

              pack();
          }// </editor-fold>//GEN-END:initComponents

          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              /* Set the Nimbus look and feel */
              //<editor-fold defaultstate= " collapsed " desc= " Look and feel setting code (optional) " >
              /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
               * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
               */
              final boolean USE_LOOK_AND_FEEL = false;
              if (USE_LOOK_AND_FEEL) {
                  try {
                      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                          if ( " Nimbus " .equals(info.getName())) {
                              javax.swing.UIManager.setLookAndFeel(info.getClassName());
                              break;
                          }
                      }
                  } catch (ClassNotFoundException ex) {
                      java.util.logging.Logger.getLogger(RDPTest2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                  } catch (InstantiationException ex) {
                      java.util.logging.Logger.getLogger(RDPTest2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                  } catch (IllegalAccessException ex) {
                      java.util.logging.Logger.getLogger(RDPTest2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                  } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                      java.util.logging.Logger.getLogger(RDPTest2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
                  }
              }
              //</editor-fold>

              /* Create and display the form */
              java.awt.EventQueue.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      final RDPTest2 frame = new RDPTest2();
                      frame.go();
                      frame.setVisible(true);
                  }
              });
          }
          // Variables declaration - do not modify//GEN-BEGIN:variables
          private javax.swing.JButton jButton1;
          private javax.swing.JButton jButton2;
          // End of variables declaration//GEN-END:variables
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      If window is minimized before locking the screen, the CPU usage is normal. This isn't an acceptable solution because if the screen locks due to inactivity or other remote connections, the CPU spike cannot be avoided.

            aivanov Alexey Ivanov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: