- //方法一:继承Thread类,实现run方法。
- classThreadTestextendsThread{
- ThreadTest(){
- }
- publicvoidrun(){
- //codehere...
- }
- }
- //创建并启动一个线程:
- ThreadTestt=newThreadTest();
- t.start();
- //方法二:实现Runnable接口的类,实现run方法。
- classRunTestimplementsRunnable{
- RunTest(){
- }
- publicvoidrun(){
- //codehere...
- }
- }
- //创建并启动一个线程:
- RunTestr=newRunTest(143);
- newThread(r).start();