题目内容

在下列E类中【代码】输出结果是_____.import java.awt.*;import java.awt.event.*;public class E implements Runnable {StringBuffer buffer=new StringBuffer();Thread t1,t2;E() { t1=new Thread(this);t2=new Thread(this);}public synchronized void addChar(char c) {if(Thread.currentThread()==t1) {while(buffer.length()==0) {try{ wait();}catch(Exception e){}}buffer.append(c);}if(Thread.currentThread()==t2) {buffer.append(c);notifyAll();}}public static void main(String s[]) {E hello=new E();hello.t1.start();hello.t2.start();while(hello.t1.isAlive()||hello.t2.isAlive()){}System.out.println(hello.buffer); //【代码】}public void run() {if(Thread.currentThread()==t1)addChar('A') ;if(Thread.currentThread()==t2)addChar('B') ;}}

A. BA
B. A
C. B
D. AB

查看答案
更多问题

下面属于Java线程同步方法的方法有()。

A. join()
B. run()
C. wait()
D. destroy()

可让线程进入就绪状态的是()

A. 线程调用了sleep()方法时
B. 线程调用了join()方法
C. 线程调用了wait()方法时
D. 线程调用了notify()方法

下面的关键词和方法中,()不是线程同步所需要的。

A. synchronized
B. wait()
C. notify()
D. sleep()

()方法可以让某个线程等待,直到其他线程的唤醒。

A. sleep()
B. wait()
C. notify()
D. join()

答案查题题库