( 31 ) 为了支持压栈线程与弹栈线程之间的交互与同步 , 在程序的下划线处依次填入的语句是
public class IntStack{
private int idx=0;
private int[] data=new int[8];
public void push(int i){
data[idx]=i;
idx++;
}
__________
......
}
A ) synchronized()
notify()
B ) synchronized()
this.wait()
C ) synchronized()
this.notify()
D ) synchronized()
sleep()
第1题:
为了支持压栈线程与弹栈线程之间的交互与同步,应在下划线处填入的选项是
pubIis class StackTest{
private int idx=0;
private int[]data=new int[8];
public void push(int i){
synchronized(this){
______;
data[idx]=i;
idx++;
}
}
……
}
A.this.notify()
B.interrupt()
C.this .wait()
D.sleep()
第2题:
( 11 )在下列程序的下划线处,填入适当语句使程序能正确执行并输出异常栈信息。
public class ThrowableException{
public static void main(String args[]){
try{
throw new Throwable(" 这里是本人定义的异常 ");
}catch(Throwable e){
System.out.println("Caught Throwable");
System.out.println("e.getMessage(): "+e.getMessage());
System.out.println("e.toString(): "+e.toString());
System.out.println("e.printStackTrace(): ");
【 11 】 ;}}}
第3题:
为了支持压栈线程与弹栈线程之间的交互与同步,在程序的下划线处依次填入的语句是( )。 publicclass IntStack{ privateintidx=O; privateint[]data=newint[8]; public______voidpush(inti){ data[idx]=i; idx++; }
A.synchronized()
B.synchronized notify() this.wait()
C.synchronized
D.Serializable this.notify() sleep()
第4题:
下列程序的运行结果是______。 class A implements Runnable { int a; iht i = 2; A(int x) { a = x; } public void run() { while(i > 0) { System.out.println("线程" + a); i--; } } } public class Testl3 { public static void main(String[] args) { Thread a1 = new Thread(new A(1)); Thread a2 = new Thread(new A(2)); a1.start(); a2.start(); } }
A.线程1 线程1 线程2 线程2
B.线程1 线程2
C.线程1 线程2 线程1 线程2
D.线程1 线程1 线程1 线程1
第5题:
下面是一个栈类的模板,其中push函数将元素i压入栈顶,pop函数弹出栈顶元素。栈初始为空,top值为0,栈顶元素在stack[top-1]中,在下面横线处填上适当的语句,完成栈类模板的定义。
template<class t>
class Tstack
{
enum{size=1000};
T stack[size]
int top;
public:
Tsack():top(0){}
void push(const T&i){
if(top<size)
stack[top++]=i;
}
T pop()
{
if(top==O)exit(1);//栈空时终止运行
retum【 】;
}
};
第6题:
( 18 )下列对线程属性的描述中,哪些是正确的?
Ⅰ .每个线程有一个标识符
Ⅱ .每个线程需要自己执行时的寄存器和栈等现场信息
Ⅲ . 每 个线程有各自的地址空间
Ⅳ . 线程是处理器调度的独立单元
Ⅴ .线程是有生命周期的
A )仅 Ⅰ 、 Ⅱ 和 Ⅲ
B ) 仅 Ⅱ 、 Ⅲ 和 Ⅳ
C )仅 Ⅰ 、 Ⅱ 、 Ⅲ 和 Ⅴ
D )仅 Ⅱ 、 Ⅲ 、 Ⅳ 和 Ⅴ
第7题:
下列对线程属性的描述中,哪些是正确的?
Ⅰ.每个线程有一个标识符
Ⅱ.每个线程需要自己执行时的寄存器和栈等现场信息
Ⅲ.每个线程有各自的地址空间
Ⅳ.线程是处理器调度的独立单元
Ⅳ.线程是有生命周期的
A.仅Ⅰ、Ⅱ和Ⅲ
B.仅Ⅱ、Ⅲ和Ⅳ
C.仅Ⅰ、Ⅱ、Ⅳ和Ⅴ
D.仅Ⅱ、Ⅲ、Ⅳ和Ⅴ
第8题:
现代操作系统中,引入线程的主要目的是
A.提高并发度
B.每个线程拥有独立的地址空间
C.减少通信开销
D.线程之间的切换时间短
E.每个线程可以拥有独立的栈
第9题:
为了支持压栈线程与弹栈线程之间的交互与同步,在下画线处依次填入的语句是 public class IntStack { private int idx=0; private int[]data=new int[8]; public ______ void push(int i) { data[idx]=i; idx++; ______ } … }
A.synchronized() notify()
B.synchronized() this.wait()
C.synchronized() this.notify()
D.synchronized() sleep()
第10题:
为了支持压栈线程与弹栈线程之间的交互与同步,应在下画线处填入的选项是( )。
A.this.notify( )
B.interrupt( )
C.this.wait( )
D.sleep( )