题目内容
publicclassTwoThreads{
privatestaticObjectresource=newObject();
privatestaticvoiddelay(longn){
try{Thread.sleep(n);}
catch(Exceptione){System.out.print(”Error);}
}
publicstaticvoidmain(String[]args){
System.out.print(”StartMain);
newThread1().start();
delay(1000);
Threadt2=newThread2();
t2.start();
delay(1000);
t2.interrupt
delay(1000);
System.out.print(”EndMain);
}
staticclassThread1extendsThread{
publicvoidrun(){
synchronized(resource){
System.out.print(”Startl);
delay(6000);
System.out.print(”End1);
}
}
}
staticclassThread2extendsThread{
publicvoidrun(){
synchronized(resource){
System.out.print(”Start2);
delay(2000);
System.out.print(”End2);
}
}
}
}
Assumethatsleep(n)executesinexactlymmilliseconds,andallothercodeexecutesinaninsignificantamountoftime.Whatistheoutputifthemain()methodisrun?()
查看答案
搜索结果不匹配?点我反馈
更多问题