广元煌褂旅行社

當(dāng)前位置:

JAVA認(rèn)證公共基礎(chǔ)知識(shí)指導(dǎo)練習(xí)題(1)

發(fā)表時(shí)間:2015/4/10 11:39:20 來(lái)源:互聯(lián)網(wǎng) 點(diǎn)擊關(guān)注微信:關(guān)注中大網(wǎng)校微信
關(guān)注公眾號(hào)

1:

Which two CANNOT directly cause a thread to stop executing? (Choose Two)

A.Existing from a synchronized block

B.Calling the wait method on an object

C.Calling notify method on an object

D.Calling read method on an InputStream object

E.Calling the SetPriority method on a Thread object

Answer:AC。同55題

2:

public class SyncTest{

public static void main(String[] args) {

final StringBuffer s1= new StringBuffer();

final StringBuffer s2= new StringBuffer();

new Thread ()  {

public void run() {

synchronized(s1) {

s2.append(“A”);

synchronized(s2) {

s2.append(“B”);

System.out.print(s1);

System.out.print(s2);

}

}

}

}.start();

new Thread() {

public void run() {

synchronized(s2) {

s2.append(“C”);

synchronized(s1) {

s1.append(“D”);

System.out.print(s2);

System.out.print(s1);

}

}

}

}.start();

}

}

Which two statements are true? (Choose Two)

A. The program prints “ABBCAD”

B. The program prints “CDDACB”

C. The program prints “ADCBADBC”

D. The output is a non-deterministic point because of a possible deadlock condition

E. The output is dependent on the threading model of the system the program is running on.

Answer:DE

3:

What will happen when you attempt to compile and run the following code?

public class Test{

int i = 0;

public static void main(String argv[]) {

Test t = new Test();

t.myMethod();

}

public void myMethod(){

while(true) {

try {  wait();

}catch (InterruptedException e) {}

i++;

}

}

}

A. Compile time error, no matching notify within the method.

B. Compile and run but an infinite looping of the while method.

C. Compilation and run without any output.

E. Runtime Exception "IllegalMonitorStatException".

Answer: E

Note: The wait/notify protocol can only be used within code that is synchronized. In this case calling code does not have a lock on the object(not synchronized) and will thus cause an Exception at runtime.

編輯推薦:

JAVA認(rèn)證公共基礎(chǔ)知識(shí)指導(dǎo)練習(xí)題匯總

JAVA認(rèn)證考試報(bào)考指南 / 更多JAVA考試模擬試題

(責(zé)任編輯:xy)

2頁(yè),當(dāng)前第1頁(yè)  第一頁(yè)  前一頁(yè)  下一頁(yè)
最近更新 考試動(dòng)態(tài) 更多>
南汇区| 洞头县| 麦盖提县| 浦北县| 军事| 敖汉旗| 桐柏县| 宿迁市| 林芝县| 团风县| 静海县| 白山市| 达日县| 金沙县| 图木舒克市| 图们市| 鄂尔多斯市| 伊通| 凌源市| 武冈市| 巫溪县| 平果县| 上思县| 襄城县| 海安县| 金湖县| 龙井市| 崇文区| 子洲县| 武胜县| 遂川县| 温宿县| 雅安市| 祥云县| 即墨市| 抚州市| 景泰县| 白城市| 卢氏县| 张家界市| 平凉市|