⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conditiontester.java

📁 用NETBEANS做的一个关于Java的小小的demo.大家赐教
💻 JAVA
字号:
/*
 * ConditionTester.java
 *
 * Created on 2007年9月14日, 上午10:54
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package product_consumer;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 * @author Administrator
 */
public class ConditionTester {
    
    public static void main(String[] args) throws InterruptedException{
        final Basket basket = new Basket();
//定义一个producer
        Runnable producer = new Runnable() {
            public void run() {
                try {
                    basket.produce();
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        };
//定义一个consumer
        Runnable consumer = new Runnable() {
            public void run() {
                try {
                    basket.consume();
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        };
//各产生10个consumer和producer
        ExecutorService service = Executors.newCachedThreadPool();
        for(int i=0; i < 10; i++)
            service.submit(consumer);
        Thread.sleep(2000);
        for(int i=0; i<10; i++)
            service.submit(producer);
        service.shutdown();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -