首页 > 编程语言 > 详细

java多线程简单小举例

时间:2015-03-25 09:01:38      阅读:249      评论:0      收藏:0      [点我收藏+]
package com.vobile;

public class TestThread extends Thread {
    private static int threadCount = 0;
    private int threadNum = ++threadCount;
    private int i = 5;

    public void run() {
        while (true) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                System.out.println("Interrupted");
            }

            System.out.println("Thread " + threadNum + " = " + i);

            if (--i == 0)
                return;
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++)
            new TestThread().start();
    }
}

java多线程简单小举例

原文:http://blog.csdn.net/u011402596/article/details/44605023

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!