troubleshooting Question

Thread problem?

Avatar of Sphinx5
Sphinx5 asked on
6 Comments1 Solution248 ViewsLast Modified:
I've got the following code:

import java.awt.event.*;
import java.awt.*;
import java.util.*;
import java.lang.*;
import java.text.*;

public class wh

   public static boolean kcc = false;
   public static MyThread tkc = new MyThread();

   public static void main(String args[])
      engine test = new engine();

   /*I then have lots of code for buttons, but the important part is: By the way this is the button to start the thread*/

   if(kcc == false)
      kcc = true;

   /*This next button code is for the stopping the thread. This is where something goes wrong, either here or in the thread. Again I've only included the important part of the button*/

   if(kcc == true)
      kcc = false);

class MyThread extends Thread
   public void run()
         for(int n = 1; n< 200; n++)
              /*irrelevant code to the situation. I know this doesn't effect the threads start/stop procedure*/
      }(while (wh.kcc == true);

See I've got 2 possible stops in. The 1st being the fact that the stop button tells the thread to stop, and the 2nd being the fact that the main code in the thread doesn't run unless wh.kcc == true, again the stop button turns this property to false. I've got message boxes around that tell me if the thread has been called, again these do not effect the threads start/stop procedures. When I click the start button the thread starts, however when I click stop I don't know if the thread stops as I don't know where abouts to put the messagebox in the thread class, when I click start after the stop button the thread doesn't start. Any ideas would be great.

Uni ted the yar eaf orc ewi thn omer cy.

Mick Barry
Java Developer
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros