public class TestThread { public static void main(String[] args) {
MYFirstThread first = new MYFirstThread() ;//这里有错
SecondThread second = new SecondThread();;//这里有错
first.start();
second.start();
try{
System.out.println("Waiting for first thread finished..");
first.join();
System.out.println("It is a long wait!!");
System.out.println("Waking up Second thread!");
second.resume();
System.out.println("Waiting for Second Thread finished..");
second.join();
}catch (InterruptedException e) {
// TODO: handle exception
}
System.out.println("I am finished too");
} class MYFirstThread extends Thread {
public void run() {
try{
System.out.println("First Thread Start!");
sleep(1000);
System.out.println("First Thread Stoped!");
}catch (InterruptedException e){
}
}
}
class SecondThread extends Thread{
MYFirstThread first = new MYFirstThread() ;//这里有错
SecondThread second = new SecondThread();;//这里有错
first.start();
second.start();
try{
System.out.println("Waiting for first thread finished..");
first.join();
System.out.println("It is a long wait!!");
System.out.println("Waking up Second thread!");
second.resume();
System.out.println("Waiting for Second Thread finished..");
second.join();
}catch (InterruptedException e) {
// TODO: handle exception
}
System.out.println("I am finished too");
} class MYFirstThread extends Thread {
public void run() {
try{
System.out.println("First Thread Start!");
sleep(1000);
System.out.println("First Thread Stoped!");
}catch (InterruptedException e){
}
}
}
class SecondThread extends Thread{
MYFirstThread first = new MYFirstThread() ;
SecondThread second = new SecondThread();
first.start();
second.start();
try{
System.out.println("Waiting for first thread finished..");
first.join();
System.out.println("It is a long wait!!");
System.out.println("Waking up Second thread!");
second.resume();
System.out.println("Waiting for Second Thread finished..");
second.join();
}catch (InterruptedException e) {
// TODO: handle exception
}
System.out.println("I am finished too");
} class MYFirstThread extends Thread {
public void run() {
try{
System.out.println("First Thread Start!");
sleep(1000);
System.out.println("First Thread Stoped!");
}catch (InterruptedException e){
}
}
}
class SecondThread extends Thread{
public void run(){
System.out.println("Second thread Start Running!");
System.out.println("Second Thread Suspend self!");
suspend();
System.out.println("Second Thread Run again");
}
}
}
还有你的程序里面resume();和suspend();方法,是已经被淘汰的方法.不要用他们了!
public class TestThread { public static void main(String[] args) {
TestThread tt = new TestThread();
MYFirstThread first = tt.new MYFirstThread();
SecondThread second = tt.new SecondThread();
first.start();
second.start();
try{
System.out.println("Waiting for first thread finished..");
first.join();
System.out.println("It is a long wait!!");
System.out.println("Waking up Second thread!");
//second.checkAccess();
System.out.println("Waiting for Second Thread finished..");
second.join();
}catch (InterruptedException e) {
// TODO: handle exception
}
System.out.println("I am finished too");
} class MYFirstThread extends Thread {
public void run() {
try{
System.out.println("First Thread Start!");
sleep(1000);
System.out.println("First Thread Stoped!");
}catch (InterruptedException e){
}
}
}
class SecondThread extends Thread{
public void run(){
System.out.println("Second thread Start Running!");
System.out.println("Second Thread Suspend self!");
//checkAccess();
System.out.println("Second Thread Run again");
}
}
}
不写这句代码编译的时候为什么会出现
TestThread.java uses or overrides a deprecated API
和
Recompile with -deprecation for details
先谢谢了!