在调用sleep()方法时,应该捕获或者声明抛出InterruptedException异常
在调用sleep()方法时,应该捕获或者声明抛出InterruptedException异常
线程操作中,调用sleep() 方法,应捕获( )异常。 A: IOException B: ArithmeticException C: InterruptedException D: NullPointerException
线程操作中,调用sleep() 方法,应捕获( )异常。 A: IOException B: ArithmeticException C: InterruptedException D: NullPointerException
一个线程被其他的线程中断,会产生什么异常。 A: IOException B: InterruptedException C: SQLException D: ThreadNotFoundException
一个线程被其他的线程中断,会产生什么异常。 A: IOException B: InterruptedException C: SQLException D: ThreadNotFoundException
Given: Which statement is true?() A: This code can throw an InterruptedException. B: This code can throw an IllegalMonitorStateException. C: This code can throw a TimeoutException after ten minutes. D: Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally. E: A call to notify() or notifyAll() from another thread might cause this method to complete normally.
Given: Which statement is true?() A: This code can throw an InterruptedException. B: This code can throw an IllegalMonitorStateException. C: This code can throw a TimeoutException after ten minutes. D: Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally. E: A call to notify() or notifyAll() from another thread might cause this method to complete normally.
一个占有CPU资源的线程可以让休眠的线程调用()方法“吵醒”自己,即导致休眠的线程发生InterruptedException异常,从而结束休眠,重新排队等待CPU资源。 A: wait() B: interrupt() C: notify() D: sleep()
一个占有CPU资源的线程可以让休眠的线程调用()方法“吵醒”自己,即导致休眠的线程发生InterruptedException异常,从而结束休眠,重新排队等待CPU资源。 A: wait() B: interrupt() C: notify() D: sleep()
Which statement is true?() A: This code can throw an InterruptedException. B: This code can throw an IllegalMonitorStateException. C: This code can throw a TimeoutException after ten minutes. D: Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally. E: A call to notify() or notifyAll() from another thread might cause this method to complete normally. F: This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".
Which statement is true?() A: This code can throw an InterruptedException. B: This code can throw an IllegalMonitorStateException. C: This code can throw a TimeoutException after ten minutes. D: Reversing the order of obj.wait() and obj.notify() might cause this method to complete normally. E: A call to notify() or notifyAll() from another thread might cause this method to complete normally. F: This code does NOT compile unless "obj.wait()" is replaced with "((Thread) obj).wait()".
下面关于Java中线程的说法不正确的是( )。 A: 调用join()方法可能抛出异常InterruptedException B: sleep()方法是Thread类的静态方法 C: 调用Thread类的sleep()方法可终止一个线程对象 D: 线程启动后执行的代码放在其run方法中
下面关于Java中线程的说法不正确的是( )。 A: 调用join()方法可能抛出异常InterruptedException B: sleep()方法是Thread类的静态方法 C: 调用Thread类的sleep()方法可终止一个线程对象 D: 线程启动后执行的代码放在其run方法中
5.1 在(1)~(3)处填上适当的语句,使程序能正常运行。 class MyThread implements Runable { (1) { while(true){System.out.print("hello"); try { (2) //休眠1秒钟 } catch (InterruptedException e) { e.printStackTrace(); } }}} public class Demo{ public static void main(String []s){ MyThread thread1= (3) //声明创建对象thread1 Thread thread = new Thread(thread1,"线程1") thread.start(); //通过对象thread启动线程 }}
5.1 在(1)~(3)处填上适当的语句,使程序能正常运行。 class MyThread implements Runable { (1) { while(true){System.out.print("hello"); try { (2) //休眠1秒钟 } catch (InterruptedException e) { e.printStackTrace(); } }}} public class Demo{ public static void main(String []s){ MyThread thread1= (3) //声明创建对象thread1 Thread thread = new Thread(thread1,"线程1") thread.start(); //通过对象thread启动线程 }}
下列关于sleep()和yield()方法描述正确的是() A: sleep方法暂停当前线程后,会进入阻塞状态 B: yield方法调用后,线程会让步,直接进入阻塞状态 C: sleep方法声明抛出了InterruptedException,所以调用sleep方法的时候要捕获该异常,或者显示声明抛出该异常。而yield方法则没有声明抛出任务异常 D: yield方法比sleep方法有更好的可移植性,通常不要依靠sleep方法来控制并发线程的执行
下列关于sleep()和yield()方法描述正确的是() A: sleep方法暂停当前线程后,会进入阻塞状态 B: yield方法调用后,线程会让步,直接进入阻塞状态 C: sleep方法声明抛出了InterruptedException,所以调用sleep方法的时候要捕获该异常,或者显示声明抛出该异常。而yield方法则没有声明抛出任务异常 D: yield方法比sleep方法有更好的可移植性,通常不要依靠sleep方法来控制并发线程的执行
以下程序编译运行结果为.(). public class Z { public static void main(String[] args) { new Z(); } Z() { Z alias1 = this; Z alias2 = this; synchronized(alias1) { try { alias2.wait(); System.out.println("DONE WAITING"); } catch (InterruptedException e) { System.out.println("INTERR UPTED"); } catch (Exception e) { System.out.println("OTHER EXCEPTION"); } finally { System.out.println ("FINALLY"); } } System.out.println("ALL DONE"); }} A: 程序可以编译但没有任何输出. B: 程序可以编译并输出 "DONE WAITING". C: 程序可以编译并输出"FINALLY". D: 程序可以编译并输出"ALL DONE". E: 程序可以编译并输出"INTERRUPTED"
以下程序编译运行结果为.(). public class Z { public static void main(String[] args) { new Z(); } Z() { Z alias1 = this; Z alias2 = this; synchronized(alias1) { try { alias2.wait(); System.out.println("DONE WAITING"); } catch (InterruptedException e) { System.out.println("INTERR UPTED"); } catch (Exception e) { System.out.println("OTHER EXCEPTION"); } finally { System.out.println ("FINALLY"); } } System.out.println("ALL DONE"); }} A: 程序可以编译但没有任何输出. B: 程序可以编译并输出 "DONE WAITING". C: 程序可以编译并输出"FINALLY". D: 程序可以编译并输出"ALL DONE". E: 程序可以编译并输出"INTERRUPTED"