我正在尝试使用 isALive 和 join 方法,但它会抛出一个错误,例如找不到符号......请告诉我这个程序中的错误到底在哪里。以及加入方法的用途是什么。我知道这是等待线程完成,但我想要详细信息。
class newthread1 implements Runnable {
newthread1() {
Thread t = new Thread(this, "FirstThread");
System.out.println("Child Thread:" + t);
t.start();
}
public void run() {
System.out.println("We are in processing for 1st thread");
int p = 1000, t = 3;
double r = 3.5, si;
try {
si = (p * r * t) / 100;
System.out.println("Simple Interest:" + si);
} catch (ArithmeticException e) {
System.out.println("Error:" + e);
}
}
}
class newthread2 implements Runnable {
newthread2() {
Thread t = new Thread(this, "SecondThread");
System.out.println("Child Thread:" + t);
t.start();
}
public void run() {
try {
System.out.println("We are in processing for 2nd thread");
double a, r = 4.3;
int p = 1000, n = 3;
double temp = Math.pow((1 + r / 100), n);
a = temp * p;
System.out.println("Compound interest:" + a);
} catch (ArithmeticException e) {
System.out.println("Error:" + e);
}
}
}
class mainthread {
public static void main(String args[]) {
newthread1 t11 = new newthread1();
new newthread2();
boolean b = t1.t.isAlive();
System.out.println("Thread is alive:" + b);
t1.t.join();
}
}