62,615
社区成员
发帖
与我相关
我的任务
分享
class SrThread1 //Application的主类
{
public static void main(String args[])
{
SubThread first=new SubThread("first"); //Name is Thread_0
SubThread second=new SubThread("secend"); //Name is Thread_1
first.setPriority(5); //设置优先级为5级
second.setPriority(7); //设置优先级为7级
System.out.println("the priority of first thread is"+first.getPriority());
//输出数据
System.out.println("the Name of first Thread is"+first.getName());
System.out.println("the priority of second Thread is"+second.getPriority());
System.out.println("the Name of second Thread is"+second.getName());
first.start(); //启动线程first
second.start(); //启动线程second
}
}
class SubThread extends Thread //定义Thread 的子类,是用户定义的线程
{
String message;
SubThread (String message)
{
this.message=message;
} //构造方法
public void run()
{
for(int i=0;i<3;i++)
System.out.println(message+"Thread is running"); //是不是这里体现了多线程
try{sleep(100);}
catch(InterruptedException e){return;}
}
}