java线程Demo

来源:互联网 发布:淘宝直通车广告位几个 编辑:程序博客网 时间:2024/06/05 07:23
class MyThread implements java.lang.Runnable {private int threadId;public MyThread(int id) {this.threadId = id;}@Overridepublic synchronized void run() {for (int i = 0; i < 10; ++i) {System.out.println("id: " + this.threadId + " : " + i);}}}public class ThreadDemo {/** * @param args * @throws InterruptedException */public static void main(String[] args) throws InterruptedException {for (int i = 0; i < 10; ++i) {new Thread(new MyThread(i)).start();Thread.sleep(1);}}}

0 0