package thread_test;
/**
* 测试扩展Thread类实现的多线程程序
*
*/
public class TestThread extends Thread{
private int threadnum;
public TestThread(int threadnum) {
this.threadnum = threadnum;
}
@Override
public synchronized void run() {
for(int i = 0;i<1000;i++){
System.out.println("NO." + threadnum + ":" + i );
}
}
public static void main(String[] args) throws Exception {
for(int i=0; i<10; i++){
new TestThread(i).start();
Thread.sleep(1);
}
}
}
NO.0:887 NO.0:888 NO.0:889 NO.0:890 NO.0:891 NO.0:892 NO.0:893 NO.0:894 NO.7:122 NO.7:123 NO.7:124
package thread_test;
/**
* 测试扩展Thread类实现的多线程程序
*
*/
public class TestThread extends Thread{
private int threadnum;
private String flag; //标记
public TestThread(int threadnum,String flag) {
this.threadnum = threadnum;
this.flag = flag;
}
@Override
public void run() {
synchronized(flag){
for(int i = 0;i<1000;i++){
System.out.println("NO." + threadnum + ":" + i );
}
}
}
public static void main(String[] args) throws Exception {
String flag = new String("flag");
for(int i=0; i<10; i++){
new TestThread(i,flag).start();
Thread.sleep(1);
}
}
}
package thread_test;
/**
* 测试扩展Thread类实现的多线程程序
*
* @author ciding
* @createTime Dec 7, 2011 9:37:25 AM
*
*/
public class TestThread extends Thread{
private int threadnum;
public TestThread(int threadnum) {
this.threadnum = threadnum;
}
public static synchronized void staticTest(int threadnum) {
for(int i = 0;i<1000;i++){
System.out.println("NO." + threadnum + ":" + i );
}
}
public static void main(String[] args) throws Exception {
for(int i=0; i<10; i++){
new TestThread(i).start();
Thread.sleep(1);
}
}
@Override
public void run(){
staticTest(threadnum);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有