声明集成Thread类的奇数/偶数序列线程

来源:互联网 发布:图片上传java 编辑:程序博客网 时间:2024/06/09 20:00
package Thread;public class NumberThread extends Thread{private int first;public NumberThread(String name,int first){super(name);this.first=first;}public void run(){System.out.println("\n"+this.getName()+":");for(int i=first;i<50;i+=2)System.out.print(i+" ");System.out.println(this.getName()+"结束!");}public static void main(String[] args){System.out.println("currentTHrad="+Thread.currentThread().getName());NumberThread thread_odd=new NumberThread("奇数线程",1);NumberThread thread_even=new NumberThread("偶数线程",2);thread_odd.start();thread_even.start();System.out.println("activeCount="+Thread.activeCount());}}

阅读全文
0 0