51,397
社区成员




import java.util.ArrayList;
import java.util.List;
public class ThreadPriority
{
public static void main(String[]args)
{
List list = new ArrayList();
Student stu1 = new Student("张三", 130);
list.add(stu1);
Student stu2 = new Student("李四", 150);
list.add(stu2);
Student stu3 = new Student("王五", 120);
list.add(stu3);
Student stu4 = new Student("赵六", 140);
list.add(stu4);
Student stu5 = new Student("钱七", 170);
list.add(stu5);
new Score().RowSeat(list);
}
}
class Score extends Thread
{
Thread thread;
public Score(){}
public Score(String name)
{
thread=new Thread(this,name);
}
public void run()
{
System.out.println("一年一班的学生成员:"+thread.getName());
}
public void RowSeat(List list)
{
Student st=(Student)list.get(0);
Student st1=(Student)list.get(1);
Student st2=(Student)list.get(2);
Student st3=(Student)list.get(3);
Student st4=(Student)list.get(4);
Score e1=new Score(st.name);
Score e2=new Score(st1.name);
Score e3=new Score(st2.name);
Score e4=new Score(st3.name);
Score e5=new Score(st4.name);
e1.thread.setPriority(st.score/10);
e2.thread.setPriority(st1.score/10);
e3.thread.setPriority(st2.score/10);
e4.thread.setPriority(st3.score/10);
e5.thread.setPriority(st4.score/10);
e1.thread.start();
e2.thread.start();
e3.thread.start();
e4.thread.start();
e5.thread.start();
try
{
e5.thread.join();
}
catch (InterruptedException e)
{
System.out.println("等待线程结束出错:"+e.getMessage());
}
}
}
class Student
{
public String name;
public int score;
public Student(String name,int score)
{
this.name=name;
this.score=score;
}
}
import java.util.ArrayList;
import java.util.List;
public class ThreadPriority
{
public static void main(String[]args)
{
List<Student> list = new ArrayList<Student>();
Student stu1 = new Student("张三", 68);
list.add(stu1);
Student stu2 = new Student("李四", 85);
list.add(stu2);
Student stu3 = new Student("王五", 70);
list.add(stu3);
Student stu4 = new Student("赵六", 51);
list.add(stu4);
Student stu5 = new Student("钱七", 98);
list.add(stu5);
new Score().RowSeat(list);
}
}
class Score extends Thread
{
Thread thread;
public Score(){}
public Score(String name)
{
thread=new Thread(this,name);
}
public void run()
{
System.out.println("一年一班的学生成员:"+thread.getName());
}
public void RowSeat(List<Student> list)
{
Student st=(Student)list.get(0);
Student st1=(Student)list.get(1);
Student st2=(Student)list.get(2);
Student st3=(Student)list.get(3);
Student st4=(Student)list.get(4);
Score e1=new Score(st.name);
Score e2=new Score(st1.name);
Score e3=new Score(st2.name);
Score e4=new Score(st3.name);
Score e5=new Score(st4.name);
e1.thread.setPriority(st.score/10);
e2.thread.setPriority(st1.score/10);
e3.thread.setPriority(st2.score/10);
e4.thread.setPriority(st3.score/10);
e5.thread.setPriority(st4.score/10);
e1.thread.start();
e2.thread.start();
e3.thread.start();
e4.thread.start();
e5.thread.start();
try
{
e5.thread.join();
}
catch (InterruptedException e)
{
System.out.println("等待线程结束出错:"+e.getMessage());
}
}
}
class Student
{
public String name;
public int score;
public Student(String name,int score)
{
this.name=name;
this.score=score;
}
}
e1.thread.setPriority(st.score/10);
e2.thread.setPriority(st1.score/10);
e3.thread.setPriority(st2.score/10);
e4.thread.setPriority(st3.score/10);
e5.thread.setPriority(st4.score/10);
这几个都超过10了, 你尝试改为1~10以内试试