爱问知识人 爱问教育 医院库

Java多线程生产者与消费者 是什么?

首页

Java多线程生产者与消费者 是什么?

Java多线程生产者与消费者 是什么?

提交回答

全部答案

    2018-03-31 07:07:12
  •   模拟生产者与消费者实例,生产者生产一个产品,消费者就消费一个产品 ,然后生产者再生产,消费者再消费
    ***********************核心方法类****************
    package test。com;
    class Queue
    // key
    {
    int value;
    boolean bFull = false;
    public synchronized void put(int i) {
    if (!bFull) {
    value = i;
    bFull = true;
    notify();// 必须用在synchronized
    }
    try {
    wait();// 必须捕获异常
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e。
      printStackTrace(); } } public synchronized int get() { if (!bFull) try { wait();//进入 } catch (InterruptedException e) { // TODO Auto-generated catch block e。
      printStackTrace(); } bFull = false; notify(); return value; } } ***************************************************************** ************************生产者类******************************** package test。
      com; class Producter extends Thread { Queue q; Producter (Queue q) { this。q=q; } public void run() { System。out。
      println("********producter****start*****"); for(int i=1;i<10;i++) { System。out。println("producter :"+i); q。put(i); }。
      

    刘***

    2018-03-31 07:07:12

类似问题

换一换
  • 系统软件 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):