Exam A QUESTION 1Given: 2.public class Threads2 implements Runnable {3. 4. public void run() { 5. System.out.println("run."); 6. throw new RuntimeException("Problem");7. } 8. public static void main(String[] args) {9. Thread t = new Thread(new Threads2());10. t.start(); 11. System.out.println("End of method.");12. }13.} Which two can be results? (Choose two.)A.java.lang.RuntimeException: ProblemB.run. java.lang.RuntimeException: ProblemC.End of method. java.lang.RuntimeException: ProblemD.End of method.run. java.lang.RuntimeException: ProblemE.run. java.lang.RuntimeException: ProblemEnd of method.Answer: DESection: All 详解:重写(override)run()方法在该线程的start()方法被调用后,JVM会自动调用run方法来执行任务;但是重载 (overload)run()方法,该方法和普通的成员方法一样,并不会因调用该线程的start()方法而被JVM自动运行。 QUESTION 2 Which two statements are true? (Choose two.) A.It is possible for more than two threads to deadlock at once. 两个以上线程可能同时死锁。 B.The JVM implementation guarantees that multiple threads cannot enter into a deadlocked state JVM(java虚拟机)保证多线程不会进入死锁状态。 C.Deadlocked threads release once their sleep() method's sleep duration has expired. 死锁的线程在sleep()方法的睡眠时间后会立刻释放。 D.Deadlocking can occur only when the wait(), notify(), and notifyAll() methods are used incorrectly. wait(), notify(), and notifyAll()使用不正确会导致死锁。 E.It is possible for a single-threaded application to deadlock if synchronized blocks are used incorrectly. 单线程应用在synchronized 使用不正确时会死锁。 F.If a piece of code is capable of deadlocking, you cannot eliminate the possibility of deadlocking by inserting invocations of Thread.yield(). 一段代码有承受死锁能力,不能通过插入Thread.yield()的调用来评估死锁的可能性。 Answer: AF |
|