示例#1
0
    /**
     * testQueueWith1ProducerAnd1Consumer.
     *
     * @return
     */
    public static long testCacheWithSyncMapWith5ProducersAnd5Consumers()
    {
        Cache               cache           = new SyncCacheWithSyncMap();
        ProducerCache       producer1       = new ProducerCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ProducerCache       producer2       = new ProducerCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ProducerCache       producer3       = new ProducerCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ProducerCache       producer4       = new ProducerCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ProducerCache       producer5       = new ProducerCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ConsumerStockCache  consumer1       = new ConsumerStockCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ConsumerStockCache  consumer2       = new ConsumerStockCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ConsumerStockCache  consumer3       = new ConsumerStockCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ConsumerMarketCache consumer4       = new ConsumerMarketCache(cache, NB_THREADING_CACHE_TESTS / 5);
        ConsumerMarketCache consumer5       = new ConsumerMarketCache(cache, NB_THREADING_CACHE_TESTS / 5);
        Thread              producerThread1 = new Thread(new ThreadStart(producer1.run));
        Thread              producerThread2 = new Thread(new ThreadStart(producer2.run));
        Thread              producerThread3 = new Thread(new ThreadStart(producer3.run));
        Thread              producerThread4 = new Thread(new ThreadStart(producer4.run));
        Thread              producerThread5 = new Thread(new ThreadStart(producer5.run));
        Thread              consumerThread1 = new Thread(new ThreadStart(consumer1.run));
        Thread              consumerThread2 = new Thread(new ThreadStart(consumer2.run));
        Thread              consumerThread3 = new Thread(new ThreadStart(consumer3.run));
        Thread              consumerThread4 = new Thread(new ThreadStart(consumer4.run));
        Thread              consumerThread5 = new Thread(new ThreadStart(consumer5.run));
        DateTime            start           = DateTime.Now;

        producerThread1.Start();
        producerThread2.Start();
        producerThread3.Start();
        producerThread4.Start();
        producerThread5.Start();
        consumerThread1.Start();
        consumerThread2.Start();
        consumerThread3.Start();
        consumerThread4.Start();
        consumerThread5.Start();
        producerThread1.Join();
        producerThread2.Join();
        producerThread3.Join();
        producerThread4.Join();
        producerThread5.Join();
        consumerThread1.Join();
        consumerThread2.Join();
        consumerThread3.Join();
        consumerThread4.Join();
        consumerThread5.Join();
        DateTime end           = DateTime.Now;
        TimeSpan executionTime = end - start;

        Console.WriteLine("[ThreadingTest], Add " + NB_THREADING_TESTS + " object in a SyncCacheWithLock with 5 Producers and Poll with 5 Consumers,, snapshot time,"
                          + executionTime.TotalMilliseconds);
        return((long)executionTime.TotalMilliseconds);
    }
 /**
 * testQueueWith1ProducerAnd1Consumer.
 *
 * @return
 */
 public static long testCacheWithLockWith1ProducerAnd5Consumers()
 {
     Cache cache = new SyncCacheWithLock();
     ProducerCache producer1 = new ProducerCache(cache, NB_THREADING_CACHE_TESTS);
     ConsumerStockCache consumer1 = new ConsumerStockCache(cache, NB_THREADING_CACHE_TESTS / 5);
     ConsumerStockCache consumer2 = new ConsumerStockCache(cache, NB_THREADING_CACHE_TESTS / 5);
     ConsumerStockCache consumer3 = new ConsumerStockCache(cache, NB_THREADING_CACHE_TESTS / 5);
     ConsumerMarketCache consumer4 = new ConsumerMarketCache(cache, NB_THREADING_CACHE_TESTS / 5);
     ConsumerMarketCache consumer5 = new ConsumerMarketCache(cache, NB_THREADING_CACHE_TESTS / 5);
     Thread producerThread1 = new Thread(new ThreadStart(producer1.run));
     Thread consumerThread1 = new Thread(new ThreadStart(consumer1.run));
     Thread consumerThread2 = new Thread(new ThreadStart(consumer2.run));
     Thread consumerThread3 = new Thread(new ThreadStart(consumer3.run));
     Thread consumerThread4 = new Thread(new ThreadStart(consumer4.run));
     Thread consumerThread5 = new Thread(new ThreadStart(consumer5.run));
     DateTime start = DateTime.Now;
     producerThread1.Start();
     consumerThread1.Start();
     consumerThread2.Start();
     consumerThread3.Start();
     consumerThread4.Start();
     consumerThread5.Start();
     producerThread1.Join();
     consumerThread1.Join();
     consumerThread2.Join();
     consumerThread3.Join();
     consumerThread4.Join();
     consumerThread5.Join();
     DateTime end = DateTime.Now;
     TimeSpan executionTime = end - start;
     Console.WriteLine("[ThreadingTest], Add " + NB_THREADING_TESTS + " object in a SyncCacheWithLock with 1 Producer and Poll with 5 Consumers,, snapshot time,"
     + executionTime.TotalMilliseconds);
     return (long)executionTime.TotalMilliseconds;
 }