|
import java.lang.*;
public class ThreadTest
{
public static void main(String args[])
{
MyThread first= new MyThread("first");
first.setPriority(Thread.MIN_PRIORITY);
first.start();
MyThread second = new MyThread("second");
second.setPriority(Thread.MAX_PRIORITY);
second.start();
MyThread third =new MyThread("third");
third.setPriority(Thread.MAX_PRIORITY);
third.start();
second.resume();
}
}
class MyThread extends Thread
{
String name;
MyThread(String name)
{
this.name=name;
}
public void run()
{
for(int i=0;i<3;i++)
{
System.out.println(name+" "+getPriority());
if(name.equalsIgnoreCase("second")&&i==1)
{
this.suspend();
}
if(name.equalsIgnoreCase("first")&&i==1)
{
this.stop();
}
}
}
}
这段代码在windows 2003中运行结果是:
second 10
second 10
third 10
third 10
third 10
second 10
first 1
first 1
但是在Linux中运行后却得到:
first 1
first 1
second 10
second 10
third 10
third 10
third 10
second 10
文件是同一个不会变,这样排除了录入上的错误。这样的结果到底是因为java有可能倚赖操作系统的运行机制不同而导致的?还望大虾们不吝赐教 ̄ |
|