多线程

来源:互联网 发布:知乎都是五毛 编辑:程序博客网 时间:2024/04/30 01:00
package com.sysway.boss.domain.customer.cas;


import java.util.ArrayList;
import java.util.List;


public class ThreadTest {
List<MyThread> threads = new ArrayList<MyThread>();


/**
* @param args
*/
public static void main(String[] args) {
         new ThreadTest().start();
}


public void start() {
for (int i = 0; i < 10; i++) {
MyThread thread = new MyThread(Integer.toString(i));
new Thread(thread).start();
threads.add(thread);
}
}

 class MyThread implements Runnable{
private String threadCode;
        
public MyThread( String threadCode) {
this.threadCode = threadCode;
}




public String getThreadCode() {
return threadCode;
}


public void setThreadCode(String threadCode) {
this.threadCode = threadCode;
}


public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("ThreadCode:"+this.getThreadCode()+"   Value:"+i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}
}
0 0
原创粉丝点击