Given that t1 is a reference to a live thread, which is true?()A.The Thread.sleep() method can take t1 as an argument.B.The Object.notify() method can take t1 as an argument.C.The Thread.yield() method can take t1 as an argument.D.The Thread.setPriority()

题目
Given that t1 is a reference to a live thread, which is true?()

A.The Thread.sleep() method can take t1 as an argument.

B.The Object.notify() method can take t1 as an argument.

C.The Thread.yield() method can take t1 as an argument.

D.The Thread.setPriority() method can take t1 as an argument.

E.The Object.notify() method arbitrarily chooses which thread to notify.


相似考题
更多“Given that t1 is a reference to a live thread, which is true?() ”相关问题
  • 第1题:

    Given:12.Stringcsv="Sue,5,true,3";13.Scannerscanner=newScanner(csv);14.scanner.useDelimiter(",");15.intage=scanner.nextInt();Whatistheresult?()

    A.Compilationfails.

    B.Afterline15,thevalueofageis5.

    C.Afterline15,thevalueofageis3.

    D.Anexceptionisthrownatruntime.


    参考答案:D

  • 第2题:

    下列程序通过设定线程优先级,抢占主线程的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。

  • 第3题:

    下列程序的输出结果是______。 class T44 implements Runnable { public void run() { System.out.print in (Thread.currentThread ( ).getName ( ) + "运行" ); } } public class ex44 { public static void main(String[] args) { Thread t1 = new Thread(new T44(), "t1"); Thread t2 = new Thread(new T44 () , "t2"); t1 .setPriority(Thread. MAX_PRIORITY); t2.setPriority(Thread.MIN_PRIORITY); t2. start (); t1 .start (); } }

    A.t1 运行 t2 运行

    B.t2 运行 t1 运行

    C.t1 运行 t1 运行

    D.t2 运行 t2 运行


    正确答案:A

  • 第4题:

    Given:fooandbararepublicreferencesavailabletomanyotherthreads.fooreferstoaThreadandbarisanObject.Thethreadfooiscurrentlyexecutingbar.wait().Fromanotherthread,whatprovidesthemostreliablewaytoensurethatfoowillstopexecutingwait()?

    A.foo.notify();

    B.bar.notify();

    C.foo.notifyAll();

    D.Thread.notify();

    E.bar.notifyAll();


    参考答案:E

  • 第5题:

    下列程序的执行结果是______。 class A5 extends Thread { boolean b; A5 (boolean bb) { b = bb; } public void run() { System.out.println(this.getName() + "运行"); } } public class Testl5 { public static void main(String[] args) { A5 a1 = new A5(true); A5 a2 = new A5(false); if(a1.b) A1.start(); if (a2 .b) A2.start(); } }

    A.Thread-0

    B.Thread-1

    C.Thread-0

    D.Thread-1 Thread-1 Thread-0


    正确答案:A
    解析:类A5继承了Thread类,并且重写了Thread类的run()方法,调用本线程的getName()方法打印出系统给本线程定义的名称。在main()方法中,a1和a2是A5的对象,它们对应的系统默认的线程名称分别是Thread—0和Thread—1,根据类A5的类变量b的布尔值控制哪一个线程调用start()方法,这里应该是a1线程被调度执行。

  • 第6题:

    【单选题】下列哪个命令可以下载HDFS目录/user/root/live.txt

    A.hdfs dfs -get /user/root/live.txt

    B.hdfs dfs -download /user/root/live.txt

    C.hdfs dfs -put /user/root/live.txt

    D.hdfs dfs -move /user/root/live.txt


    hdfs dfs -get /hdfstest/test.txt