问题 单项选择题

下列程序通过设定线程优先级,抢占主线程的CPU,选择正确的语句填入横线处。
class T14 implements Runnable

private Boolean fStop - true;
public void run()

while(fStop)

System.out.println(Thread.currentThread().getName() + "run");
try

Thread.sleep(l);

catch(Exception e)

e.printStackTrace();



public void stopRun()

fStop = false;


public class Testl4

public static void main(String[] args)

T14 t14 = new T14();
Thread t1 = new Thread(ti4, "T14");
Thread t = Thread.currentThread()’;
______;
Ti.start();
T14.stopRun();
System.out.println ( "stop ");

A.setPriority(Thread. MIN_PRIORITY)

B.t1 .setPriority(Thread. MIN_PRIORITY)

C.t.setPfiofity(Thread. MIN_PRIORITY)

D.t14.setPriority(Thread. MIN_PRIORITY)

答案

参考答案:C

解析: 使用setPriority方法来设定线程的优先级,程序中的t是主线程,t1是创建的线程, t6是实现了Runnable接口的类的实例,由于使用的参数是MIN_PRIORITY,因此是将主线程 t的优先级设为最低,这样t1才能抢占t的CPU。

单项选择题 A1型题
单项选择题