多线程
来源:互联网 发布:知乎都是五毛 编辑:程序博客网 时间: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();
}
}
}
}
}
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
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 百度地图 定位问题
- SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
- hiredis发布/订阅示例
- 形参和实参
- 使用HiRedis在开发过程中需要注意的事情1
- 多线程
- CXF的webService服务端用到的jar包
- 1.0虚拟机的基本操作指令
- 理解Linux系统负荷
- ArcGIS Engine代码共享-投影(SpatialReference)对象操作
- POJ2796 Feel Good(单调栈)
- 介绍GLSurfaceView
- Hibeernate中的两种分页方式
- 编译pano13的一些注意事项