JDK-4878438 : CPU spikes to 100% with awt applet using appletviewer and plugin IE5
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0,1.4.1_02
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-06-13
  • Updated: 2003-09-03
  • Resolved: 2003-09-03
Related Reports
Duplicate :  
Relates :  
Description
filed under appletviewer but also seen in the plugin on IE5.

Example code:  (See attached file: BurnCpuApplet.jar)  The class file is
compiled using 1.4.1_02, will not run on 1.3.x (you must recompile the
source).

Installation Instructions: To run the applet example locally, configure
your IDE to use 1.4.1_02 plugin and run the applet within the AppletViewer.
                      To run the example within IE, install (See attached
file: BurnCpuApplet.jsp)and the above jar file in the same directory within
a servlet engine.
                      To run as a standalone app, just launch with java -cp
BurnCpuApplet.jar sun.java.bug.BurnCpuApplet
Dependencies: rt.jar

to run it with appletviewer
java -cp BurnCpuApplet.jar sun.applet.AppletViewer BurnCpuApplet.html

the html file is attached and only contains the line
<applet code="sun.java.bug.BurnCpuApplet.class" width=584 height=200> </applet>
Problem demonstration: Click on Choice box and select 'blue panel'.  Text
'blue panel takes flip#1' will show immediately.  Then select 'red panel'.
The text 'red panel takes flip#2' will show after approx. 5 seconds.
During this period CPU utilization goes to 100%.  This will happen with all
subsequent Choice selection.

Observations:
   Problem can be reproduced by running 1.4.1_02 AppletViewer or Java
   plugin within IE5.x
   The applet runs fine on 1.3.1._08
   The applet runs fine within IE6.x on either 1.3 or 1.4
   The standalone version runs fine on either 1.3 or 1.4
   Thread profiling showed that AWT-Windows thread spends almost 100% CPU
   within native method WToolkit.eventLoop().  This considerably slows
   performance of the entire system, including other JVM threads.
   The source level debugging showed that this burst of CPU activity inside
   native event loop (AWT-Windows) happens between two native calls in
   WComponentPeer(): WCanvasPeer.create(WComponentPeer wc) and
   WComponentPeer.start() in AWT-EventQueue-1 thread (see below).

    WComponentPeer(Component component)
    {
        isLayouting = false;
        paintPending = false;
        oldWidth = -1;
        oldHeight = -1;
        numBackBuffers = 0;
        backBuffer = null;
        serialNum = 0;
        target = component;
        paintArea = new RepaintArea();
        Container container = WToolkit.getNativeContainer(component);
        WComponentPeer wcomponentpeer
= (WComponentPeer)WToolkit.targetToPeer(container);
        create(wcomponentpeer);
        surfaceData = Win32SurfaceData.createData(this, numBackBuffers);
        initialize();
        start();
    }

Comments
EVALUATION I doubt this is an appletviewer bug. I wonder if it is related to 4673954? ###@###.### 2003-06-13 This could be the same bug as 4673954. I've had similar experiences with reproducing this bug - it's okay w/ 1.3.1, but pegs the CPU in all releases since 1.4. ###@###.### 2003-06-16 This is almost certainly the same problem as 4673954 . The characteristic 5 second period where CPU jumps to 100% is the same here. ###@###.### 2003-08-29 I verified that this is the same problem as 4745222 and 4673954. ###@###.### 2003-09-03
29-08-2003

WORK AROUND The testcase is doing something noticeably & logically incorrect. It adds and removes the same components in it's initCard() methods . The bug can be worked around by making some small changes to the testcase. Two workarounds I came-up with are here: i) Change the code in the initCards() method as follows: //commented code is original code which is buggy .. // with this change there is no need to have redPanel and bluePanel in the class // private void initCards(String cardName, String msg) { cards.removeAll(); //Panel currPanel = cardName.startsWith("red") ? redPanel : blue Panel; Panel currPanel = new Panel(); if( cardName.startsWith("red") ) { currPanel.setBackground(Color.red); System.out.println("Red Panel " ); } else { System.out.println("Blue Panel " ); currPanel.setBackground(Color.blue); } //currPanel.removeAll(); currPanel.add(new Label(cardName)); currPanel.add(new Label(msg)); cards.add(currPanel, cardName); cards.validate(); cards.doLayout(); } ii) We can optimize the code to do initialization once for all and *not* calling cards.add() in the initCard() source diff is here: diff BurnCpuApplet.java t/BurnCpuApplet.java (original code) 12d11 < import java.io.*; 81,82d79 < redPanel.add(new Label(RED_PANEL)); < redPanel.add(new Label("This is a red panel") ); 84d80 < 86,87d81 < bluePanel.add(new Label(BLUE_PANEL) ); < bluePanel.add(new Label("This is a blue panel" )); 92,93c86 < < //initCards(RED_PANEL, "started"); --- > initCards(RED_PANEL, "started"); 95,97d87 < cards.add(redPanel, RED_PANEL); < cards.add(bluePanel, BLUE_PANEL); < 117,124d106 < Panel currPanel = cardName.startsWith("red") ? redPanel : bluePanel; < < Label curLabel = (Label) currPanel.getComponent(0) ; < < curLabel.setText(cardName + " " + msg ); < < /*** < Why to initialize every time ?? 130a113 > 133d115 < **/ ###@###.### 2003-07-07
07-07-2003