Search code examples
javaappletthread-safetythreadpooljchart2d

How to kill or stop other threads in java applet


In java applet I am plotting chart By JCChart. Now after plotting the chart when I watch the task scheduler then it show that cpu utilization is still greater then 50 by Java.exe. Now I use JConsole with plugin to watch which thread in java taking the much CPU utilization. Then it shows that AWT-EventQueue-2 is taking major time And this thread is in Runnable state and never starts. and what it doing is that some like below..

sun.java2d.loops.FillRect.FillRect(Native Method)
sun.java2d.pipe.LoopPipe.fillRect(Unknown Source)
sun.java2d.pipe.ValidatePipe.fillRect(Unknown Source)
sun.java2d.SunGraphics2D.fillRect(Unknown Source)
com.klg.jclass.chart.JCChart.paintComponent(JCChart.java:670)
javax.swing.JComponent.paint(Unknown Source)
com.klg.jclass.chart.JCChart.paint(JCChart.java:593)
javax.swing.JComponent.paintChildren(Unknown Source)
javax.swing.JComponent.paint(Unknown Source)

So can any body tell me how can I prevent my applet from such type of happening or how can I stop this.


Solution

  • The recommended way of stopping a thread in Java is to implement the logic in such way that the thread will finish the execution on his own. If you have a loop you can consider ending it based on an action (eg. user clicked stop button of finish). From your details it seems that the applet is repainting. Probably you should look on what is triggering the repaint.