解决方案 »

  1.   

    try {
    Broker broker = new Broker(); int consumerCount = 10;
    ExecutorService threadPool = Executors
    .newFixedThreadPool(consumerCount + 1); for (int i = 0; i < consumerCount; ++i) {
    DatabaseFactory.getInstance().saveAliasAs("consumer" + i);
    threadPool.execute(new Consumer("consumer" + i, broker));
    } Future producerStatus = threadPool.submit(new Producer(broker)); // this will wait for the producer to finish its execution.
    producerStatus.get(); threadPool.shutdown();
    threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (Exception e) {
    StackUtility.logStackTrace(log, e);
    }
      

  2.   

    public class Broker {
    public ArrayBlockingQueue<FileWrapper> queue = new ArrayBlockingQueue<FileWrapper>(
    4000);
    public Boolean continueProducing = Boolean.TRUE; public void put(FileWrapper data) throws InterruptedException {
    this.queue.put(data);
    } public FileWrapper get() throws InterruptedException {
    // return this.queue.take();
    return this.queue.poll(3, TimeUnit.SECONDS);
    }
    }
      

  3.   

    AMD 3核心的 红帽子 linux,连接的是mySQL 数据库。10个消费线程从队列里往数据库保存数据,一个生产线程扫描磁盘!
      

  4.   

    配置可以啊,你开10个线程,输入top -b -n 2,监控下cpu和内存的变化。