介绍java多线程例子
t.join(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
class TestThread extends Thread {
public void run() {
while(true) {
System.out.println("TestThread:
"+Thread.currentThread().getName() + " is running");
}
}
}
当main线程运行10000下后,与TestThread 联合10秒,其实就是让TestThread 运行10秒,然后在分别运行。
Java 多线程例子4 继承Thread 实现Runnable
class TestThread extends Thread {
public void run() {
while(true) {
System.out.println("TestThread:
"+Thread.currentThread().getName() + " is running");
}
}
}
class ThreadDemo {
public static void main(String[] args) {
TestThread t = new TestThread();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
}
}
class TestThread implements Runnable {
int tickets = 100;
public void run() {
while(true) {