Esempio n. 1
0
        //Об'єктний пул - Object Pool
        public Run ObjectPool()
        {
            Console.WriteLine("\nObject Pool:");

            Console.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name);
            var reusablePool = new ReusablePool();

            var thrd1       = new Thread(RunObjectPool);
            var thrd2       = new Thread(RunObjectPool);
            var thisObject1 = reusablePool.GetObject();
            var thisObject2 = reusablePool.GetObject();

            thrd1.Start(reusablePool);
            thrd2.Start(reusablePool);
            ViewObject(thisObject1);
            ViewObject(thisObject2);
            Thread.Sleep(2000);
            reusablePool.Release(thisObject1);
            Thread.Sleep(2000);
            reusablePool.Release(thisObject2);

            return(this);
        }
Esempio n. 2
0
        //Об'єктний пул - Object Pool
        public Run ObjectPool()
        {
            Console.WriteLine("\nObject Pool:");

            Console.WriteLine(System.Reflection.MethodInfo.GetCurrentMethod().Name);
            var reusablePool = new ReusablePool();

            var thrd1 = new Thread(RunObjectPool);
            var thrd2 = new Thread(RunObjectPool);
            var thisObject1 = reusablePool.GetObject();
            var thisObject2 = reusablePool.GetObject();
            thrd1.Start(reusablePool);
            thrd2.Start(reusablePool);
            ViewObject(thisObject1);
            ViewObject(thisObject2);
            Thread.Sleep(2000);
            reusablePool.Release(thisObject1);
            Thread.Sleep(2000);
            reusablePool.Release(thisObject2);

            return this;
        }