ITeye博客

Java创建线程的两种方法

zwfc · 2008-12-18 13:50 · Markdown

  1. //方法一:继承Thread类,实现run方法。
  2. classThreadTestextendsThread{
  3. ThreadTest(){
  4. }
  5. publicvoidrun(){
  6. //codehere...
  7. }
  8. }
  9. //创建并启动一个线程:
  10. ThreadTestt=newThreadTest();
  11. t.start();
  12. //方法二:实现Runnable接口的类,实现run方法。
  13. classRunTestimplementsRunnable{
  14. RunTest(){
  15. }
  16. publicvoidrun(){
  17. //codehere...
  18. }
  19. }
  20. //创建并启动一个线程:
  21. RunTestr=newRunTest(143);
  22. newThread(r).start();

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。