Java线程学习(一)

 1 package com.xyzx.thread;
 2 
 3 public class ThreadDemo extends Thread{
 4     
 5     public void run(){
 6         Thread thread = Thread.currentThread();
 7         for (int i = 0; i < 10; i++) {
 8             System.out.println("正在运行"+thread.getName() + ",运行次数:" + i);
 9         }
10     }
11 
12     public static void main(String[] args) {
13         ThreadDemo threadDemo = new ThreadDemo();
14         threadDemo.start();
15         for (int i = 0; i < 10; i++) {
16             System.out.println("正在运行的线程:" + Thread.currentThread().getName() + ", 运行次数:" + i);
17         }
18     }
19 }

结果:

 

posted @ 2018-09-21 17:59  stujike123456  阅读(116)  评论(0编辑  收藏  举报