实现多线程的方法有3种:
1.继承thread类
eg : 定义: public class firstThread extends Thread
调用: firstThread ft = new firstThread();
ft.start();
2.实现Runnable接口
eg : 定义: public class MyRunnable implements Runnable
调用: MyRunnable mr = new MyRunnable();
Thread tr = new Thread(mr);
tr.start();
3.运用Timer 和 TimerTask 类实现
eg : 创建Timer
Timer t = new Timer();
创建TimerTask
MyTimerTask mtt1 = new MyTimerTask("线程1:");
启动线程
t.schedule(mtt1, 0);
1.继承thread类
eg : 定义: public class firstThread extends Thread
调用: firstThread ft = new firstThread();
ft.start();
2.实现Runnable接口
eg : 定义: public class MyRunnable implements Runnable
调用: MyRunnable mr = new MyRunnable();
Thread tr = new Thread(mr);
tr.start();
3.运用Timer 和 TimerTask 类实现
eg : 创建Timer
Timer t = new Timer();
创建TimerTask
MyTimerTask mtt1 = new MyTimerTask("线程1:");
启动线程
t.schedule(mtt1, 0);