R
repairman2003
I'm having some trouble understanding how to set up a thread to pause
execution when some other thread meets some condition. I'm using a
base class and then at least 2 classes that extends Thread. The
threads don't share any data among each other, just between the thread
and the base class. The baseClass just starts the other threads and
outputs information to the screen. For some background this is a
robotics project so the threads are moving the robot and reading
data. If certain threads aren't paused they will conflict with each
other.
Here is a basic view of the classes:
public class baseClass
{
thread1 thread1Obj = new thread1();
thread2 thread2Obj = new thread2();
....
void upDateScreen()
{
thread1Obj.start();
thread2Obj.start();
while(true)
{
//output things to screen
}
}
}
class thread1 extends Thread
{
int x = 0;
void run()
{ //At the present moment, everything inside the run() is in an
infinite loop. This can change if necessary
//Read x in from a sensor
if(x<10)
//Pause all other threads so this one can do what it
needs to do
...
}
}
class thread2 extends Thread
{
void run()
{
...
}
}
How do I set it up so that thread2 is paused while thread1 is doing
something important?
Thanks
execution when some other thread meets some condition. I'm using a
base class and then at least 2 classes that extends Thread. The
threads don't share any data among each other, just between the thread
and the base class. The baseClass just starts the other threads and
outputs information to the screen. For some background this is a
robotics project so the threads are moving the robot and reading
data. If certain threads aren't paused they will conflict with each
other.
Here is a basic view of the classes:
public class baseClass
{
thread1 thread1Obj = new thread1();
thread2 thread2Obj = new thread2();
....
void upDateScreen()
{
thread1Obj.start();
thread2Obj.start();
while(true)
{
//output things to screen
}
}
}
class thread1 extends Thread
{
int x = 0;
void run()
{ //At the present moment, everything inside the run() is in an
infinite loop. This can change if necessary
//Read x in from a sensor
if(x<10)
//Pause all other threads so this one can do what it
needs to do
...
}
}
class thread2 extends Thread
{
void run()
{
...
}
}
How do I set it up so that thread2 is paused while thread1 is doing
something important?
Thanks