运行下列程序,产生的结果是 ()。public class Example12_1 extends Thread implements Runnable{public void run(){System.out.println("this is run()");}public static void main(String args[]){Thread t=new Thread(new Example12_1();t.start();}}
A. 第一行会产生编译错误
B. 第六行会产生编译错误
C. 第六行会产生运行错误
D. 程序会运行和启动
查看答案
在下列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()