Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

help with Thread security

  Asked By: Everett    Date: Jul 20    Category: Java    Views: 696
  

I am having some problems with threads. The easiest way to
illustrate my troubles is with some examples. So here goes:


Say I want to create a class which is a sub-class of thread
eg.

public class ThreadClass extends Thread
{
public void run()
{/*Stick stuff here*/}
}

But say I also wanted to be able to modify attributes of that
Thread while it is running
eg.

public class ThreadClass extends Thread
{
boolean attr; //an attribute that will determine whether
//the thread is to continue running

public void run()
{
attr = true;
while( attr )
{
/* STICK STUFF HERE */
}
}

public void discontinue()
{
attr = false;
}
}

My Question is, how would I use such a class so that I would
be aloud to call the discontinue method from an external class
(or a similar method that would modify some kind of attribute
of the Thread class)

Any explanations would be deeply appreciated.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on help with Thread security Or get search suggestion and latest updates.




Tagged: