分享

ocjp题库试题详解(一)

 _小女子_ 2015-01-23
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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多