Controlling individual threads
Hi, I am new to threads and have made a test program. The code is short. I am trying to control each thread. I am not sure if my method is right. Can someone please help? I can not find the answer in books or on the internet, though, it could be my own mindset. I am getting the following error:
############# Start javac output #########################
exec: javac -g threadTest.java
threadTest.java:13: cannot find symbol
symbol : method getcalcDone()
location: class java.lang.Thread
while (t1.getcalcDone() == false); //This loop will run till thread 1 has made it's calculation.
^
threadTest.java:21: cannot find symbol
symbol : variable t1
location: class threadTest
t1.calc(5, 3); // This SHOULD add 5 and 3 together. Not sure if I can control individual threads like this.
^
threadTest.java:22: cannot find symbol
symbol : variable t1
location: class threadTest
t2.calc(t1.results, 10); // Add the results of the first calculation and 10 together.
^
threadTest.java:22: cannot find symbol
symbol : variable t2
location: class threadTest
t2.calc(t1.results, 10); // Add the results of the first calculation and 10 together.
^
4 errors
############# End javac output #########################
Code:
import java.util.*;
public class threadTest extends Thread
{
public static void main(String[] args)
{
Thread t1 = new threadTest();
Thread t2 = new threadTest();
t1.start();
while (t1.getcalcDone() == false); //This loop will run till thread 1 has made it's calculation.
t2.start();
}
public void run()
{
t1.calc(5, 3); // This SHOULD add 5 and 3 together. Not sure if I can control individual threads like this.
t2.calc(t1.results, 10); // Add the results of the first calculation and 10 together.
}
}
class Thread1 extends Thread
{
int a = 0;
int b = 0;
int results = 0;
boolean calcDone = false;
public Thread1(int a, int b)
{
this.a = a;
this.b = b;
}
void calc(int a, int b)
{
results = a + b;
calcDone = true;
}
boolean getcalcDone()
{
return calcDone;
}
}
Thank you for any ideas.
Youngstorm