本题程序中实现了一个“生产者一消费者问题”。生产者产生一个随机数存入DataPool

题型:问答题

问题:

本题程序中实现了一个“生产者一消费者问题”。生产者产生一个随机数存入DataPool类中,消费者从中取出数据。DataPool类一次只能存放一个数据。请更正题中带下划线的部分。
注意:不改变程序的结构,不得增行或删行。
class DataPool

private int data;
private boolean isFull;
public DataPool()

isFull=false;

public synchronized void putData(int d)

if(isFull= =true)

try

this.notify();

catch(InterruptedException e)


data=d;
isFull=true;
System.out.println("生产了一个数据:"+data);
this.notify();

public synchronized int getData()

if(isFull= =false)

try

this.wait();

catch(InterruptedException e)


isFull=false;
System.out.println("消费了一个数据"+data);
this.wait();
return this.data;

boolean getIsFull()

return isFull;


class Producer extends Thread

DataPool pool;
public Producer(DataPool pool)

this.pool=pool;

public void run()

for(int i=0; i<10; i++)

int data=(int) (Math.random()*1000);
try
//用于生产数据
sleep(data);

catch(InterruptedException e)

pool.putData(data);



class Consumer implements Runnable

DataPool pool;
public Consumer(DataPool pool)

this.pool=pool;

public void run()

for(int i=0; i<10; i++)

int data=pool.getData();
try
//用于处理数据
sleep((int) (Math.random()*1000));

catch(InterruptedException e)




public class advance

public static void main(String[] args)

Data Pool pool=new Data Pool();
Producer pro=new Producer(pool);
Runnable con=new Consumer(pool);
Thread conTh=new Thread(con);
pro.start();
conTh.start();

考点:计算机等级考试JAVA二级JAVA机试
题型:问答题
在语句PRINT  3,3+2的结果是(  )
A.3,3+2B.3,5C.3,5D.3,2+3
题型:问答题

隧道衬砌裂缝注浆嘴及注浆管应设于裂缝的交叉处、较宽处及贯穿处等部位。对封缝的()应进行检查。

题型:问答题

从月进货总量上看,可以对(  )的零售户实施监控,有效解决零售大户的不规范经营和大户控制小户问题。

A.月进货数量较大

B.月进货次数较多

C.月进货品牌单一

D.月进货量波动较大

题型:问答题

1938年10月广州沦陷后,中共先后组建了以王作尧为队长的东宝惠人民抗日游击队、以()为总队长的惠宝人民抗日游击总队和冯白驹领导的抗日游击队等武装,有效打击了日本侵略者,开辟了华南敌后战场。

A、曾生

B、林平

C、梁鸿钧

D、杨康华

题型:问答题

圈地运动

更多题库