参考答案和解析
InterruptedException
更多“Thread类的sleep方法会抛出()异常。”相关问题
  • 第1题:

    GiventhatTriangleimplementsRunnable,and:Whichtwostatements,insertedindependentlyatbothlines35and41,tendtoallowboththreadstotemporarilypauseandallowtheotherthreadtoexecute?()

    A.Thread.wait();

    B.Thread.join();

    C.Thread.yield();

    D.Thread.sleep(1);

    E.Thread.notify();


    参考答案:C, D

  • 第2题:

    下列哪些方法是Thread类中所定义的方法?()

    A.yield()

    B.sleep(longmsec)

    C.go()

    D.stop()


    参考答案:A, B, D

  • 第3题:

    下列方法中,声明抛出InterruptedException类型异常的方法是

    A.suspended()

    B.resume()

    C.sleep()

    D.start()


    正确答案:C

  • 第4题:

    下列程序的功能是在监控台上每隔-秒钟显示-个字符串”Hello!¨,能够填写在程序中下画线位置,使程序完整并能正确运行的语句是( )。

    A.sleep(1000)

    B.t. sleep(1000) InterruptedExceptionInterruptedException

    C.Thread. sleep(1000)

    D.Thread. sleep(1000) RuntimeExceptionlnterruptedException


    正确答案:D
    本题考查Java中的线程和异常处理。题目首先通过实现Runnable接口创建线程,Testt=newTest()语句定义了Test的1个实例,Threadtt=newThread(t)定义了1个名为tt的线程,tt.slart()语句启动线程。通过try-catch语句来处理异常。try代码包括-些简单语句或方法调用,遇到异常情况时,停止执行而跳转到相应处理异常的程序,然后由catch来控制。题目要求每间隔ls输出.间隔使用Thread.sleep(1000)语句来实现,调用InterruptedExceI)lion来完成。RuntimeExeeption类包含有较多子类,比如,算术异常ArithmeticException,当除法分母为0等时使用;索引越界异常IndexOutOfBoundsException等。

  • 第5题:

    判断下列语句哪个正确()。

    • A、在线程休眠时,sleep方法会占用处理器时间
    • B、将方法声明为synchronized,就可以确保不会发生死锁
    • C、不提倡使用Thread类的suspend方法,resume方法和stop方法
    • D、以上描述都正确

    正确答案:D

  • 第6题:

    下面哪个不是Thread类的方法?()

    • A、yield()
    • B、sleep(longmsec)
    • C、go()
    • D、stop()

    正确答案:C

  • 第7题:

    下面方法不属于Thread类里面的是()

    • A、run();
    • B、sleep();
    • C、wait();
    • D、yield();

    正确答案:C

  • 第8题:

    下面()让线程休眠1分钟。 

    • A、Thread.Sleep(1)
    • B、Thread.Sleep(60)
    • C、Thread.Sleep(1000)
    • D、Thread.Sleep(60000)

    正确答案:D

  • 第9题:

    单选题
    给你如下一段代码: 你需要在类中编写更多的代码,用最少的资源每隔30秒去运行DoWork( )方法()
    A

    Thread.Sleep(30000)

    B

    Thread.SpinWait(30000)

    C

    Thread.QueueUserWorkItem(30000)

    D

    Thread.SpinWait(30)


    正确答案: C
    解析: 暂无解析

  • 第10题:

    多选题
    Which two of statements are true?()
    A

    It is possible to synchronize static methods.

    B

    When a thread has yielded as a result of yield(), it releases its locks.

    C

    When a thread is sleeping as a result of sleep(), it releases its locks.

    D

    The Object.wait() method can be invoked only from a synchronized context.

    E

    The Thread.sleep() method can be invoked only from a synchronized context.

    F

    When the thread scheduler receives a notify() request, and notifies a thread, that thread immediately releases its lock.


    正确答案: C,B
    解析: 暂无解析

  • 第11题:

    单选题
    现有:  5.  class Order2 implements Runnable  {     6.    public void run()  {     7. for (int x- o;  x<4;  x++)  {  8. try{Thread.sleep(100);  )catch  (Exception e)  {  }     9.    System.out.print("r");     10.    }  }  11.    public static void main(string  []  args)  {     12.    Thread t=new Thread(new order2());     13.    t.start();  14.    for(int x=0;  x<4;  x++)  {     15.    //insert code here     16.    System.out.print("m");     17.  }  }  }  哪一个插入到第15行,最有可能产生输出 rmrmrmrm?()
    A

      Thread.sleep(1);

    B

      Thread.sleep(100);

    C

      Thread.sleep(1000);

    D

      try{  Thread.sleep(1);  )  catch  (Exception e)  {  }

    E

      try{Thread.sleep(100);  )  catch  (Exception  e)  {  }

    F

      try{Thread.sleep(1000);  )  catch  (Exception  e)  { }


    正确答案: F
    解析: 暂无解析

  • 第12题:

    单选题
    在J2EE 中,VetoableChangeSupport的fireVetoableChange方法会抛出的异常是()。
    A

    PropertyException

    B

    PropertyVetoException

    C

    VetoException

    D

    PropertyChangeException


    正确答案: C
    解析: 暂无解析

  • 第13题:

    哪两个java.lang.Thread方法抛出受检异常?()

    A.run

    B.join

    C.sleep

    D.start


    参考答案:B, C

  • 第14题:

    5.classOrder2implementsRunnable{6.publicvoidrun(){7.for(intx=0;x〈4;x++){8.try{Thread.sleep(100);}catch(Exceptione){}9.System.out.print("r");10.}}11.publicstaticvoidmain(String[]args){12.Threadt=newThread(newOrder2());13.t.start();14.for(intx=0;x〈4;x++){15.//insertcodehere16.System.out.print("m");17.}}}哪一个插入到第15行,最有可能产生输出rmrmrmrm?()

    A.Thread.sleep(1);

    B.Thread.sleep(100);

    C.Thread.sleep(1000);

    D.try{Thread.sleep(100);}catch(Exceptione){}


    参考答案:D

  • 第15题:

    以下不属于Thread类提供的线程控制方法的是( )。

    A.bmak()

    B.sleep()

    C.yield()

    D.join()


    正确答案:A

  • 第16题:

    下列方法可以通过Thread类就可以调用,而不需要通过Thread类的实例进行调用的是 ( )

    A.sleep()

    B.start()

    C.setPriority()

    D.suspend()


    正确答案:A
    解析:sleep()方法可以通过Thread类就可以调用,而不需要通过Thread类的实例进行调用。

  • 第17题:

    下列哪些方法是Thread 类中所定义的方法?()

    • A、yield()
    • B、sleep(long msec)
    • C、go()
    • D、stop()

    正确答案:A,B,D

  • 第18题:

    下面关于Java中线程的说法不正确的是()

    • A、调用join()方法可能抛出异常InterruptedException。
    • B、sleep()方法是Thread类的静态方法。
    • C、调用Thread类的sleep()方法可终止一个线程对象。
    • D、线程启动后执行的代码放在其run方法中。

    正确答案:C

  • 第19题:

    现有:   class Thread2 implements Runnable {   void run() {   System.out.print("go ");   }   public static void main(String [] args) {   Thread2 t2 = new Thread2();   Thread t = new Thread(t2);   t.start();   }   }   结果为:()

    • A、 go
    • B、 编译失败
    • C、 代码运行,无输出结果
    • D、 运行时异常被抛出

    正确答案:B

  • 第20题:

    5. class Order2 implements Runnable {  6. public void run() {  7. for(int x = 0; x 〈 4; x++) {  8. try { Thread.sleep(100); } catch (Exception e) { }  9. System.out.print("r");  10. } }  11. public static void main(String [] args) {  12. Thread t = new Thread(new Order2());  13. t.start();  14. for(int x = 0; x 〈 4; x++) {  15. // insert code here  16. System.out.print("m");  17. } } }  哪一个插入到第15行,最有可能产生输出 rmrmrmrm ?()  

    • A、Thread.sleep(1);
    • B、Thread.sleep(100);
    • C、Thread.sleep(1000);
    • D、try { Thread.sleep(100); } catch (Exception e) { }

    正确答案:D

  • 第21题:

    多选题
    哪两个java.lang.Thread 方法抛出受检异常?()
    A

    run

    B

    join

    C

    sleep

    D

    start


    正确答案: D,C
    解析: 暂无解析

  • 第22题:

    单选题
    判断下列语句哪个正确()。
    A

    在线程休眠时,sleep方法会占用处理器时间

    B

    将方法声明为synchronized,就可以确保不会发生死锁

    C

    不提倡使用Thread类的suspend方法,resume方法和stop方法

    D

    以上描述都正确


    正确答案: C
    解析: 暂无解析

  • 第23题:

    单选题
    下面关于Java中线程的说法不正确的是()
    A

    调用join()方法可能抛出异常InterruptedException。

    B

    sleep()方法是Thread类的静态方法。

    C

    调用Thread类的sleep()方法可终止一个线程对象。

    D

    线程启动后执行的代码放在其run方法中。


    正确答案: C
    解析: 暂无解析

  • 第24题:

    单选题
    class Thread2 implements Runnable {   void run() {    System.out.print("go ");    }   public static void main(String [] args) {   Thread2 t2 = new Thread2();   Thread t = new Thread(t2);   t.start();    }    }    结果为:()
    A

     go

    B

     编译失败

    C

     代码运行,无输出结果

    D

     运行时异常被抛出


    正确答案: D
    解析: 暂无解析