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());
}
}
声明集成Thread类的奇数/偶数序列线程
最新推荐文章于 2022-11-11 21:16:15 发布