---
title: "Java创建线程的两种方法 "
author: "zwfc"
date: "2008-12-18T13:50:00Z"
tags: []
slug: "java"
draft: false
lastmod: "2008-12-18T13:50:00Z"
id: 470947
url: "https://zwfc.iteye.com/blog/470947"
---

02. //方法一：继承Thread类，实现run方法。
03. classThreadTestextendsThread{
04. ThreadTest(){
05. }
06. publicvoidrun(){
07. //codehere...
08. }
09. }
10. //创建并启动一个线程：
11. ThreadTestt=newThreadTest();
12. t.start();
13. //方法二：实现Runnable接口的类，实现run方法。
14. classRunTestimplementsRunnable{
15. RunTest(){
16. }
17. publicvoidrun(){
18. //codehere...
19. }
20. }
21. //创建并启动一个线程：
22. RunTestr=newRunTest(143);
23. newThread(r).start();