1: using System;
2: using Spring.Pool.Support;
3:
4: namespace SpringSeries.Core.ObjectPooling
5: {
6: class Program
7: {
8: static void Main(string[] args)
9: {
10: DateTime _time = DateTime.Now;
11:
12: SimplePool _pool = new SimplePool(new BigObjectPoolableFactory(), 4);
13:
14: Console.WriteLine("Richiedo tre oggetti");
15: BigObject _bigobj1 = _pool.BorrowObject() as BigObject;
16: Console.WriteLine(_bigobj1.DoWork());
17: BigObject _bigobj2 = _pool.BorrowObject() as BigObject;
18: Console.WriteLine(_bigobj2.DoWork());
19: BigObject _bigobj3 = _pool.BorrowObject() as BigObject;
20: Console.WriteLine(_bigobj3.DoWork());
21:
22: Console.WriteLine("Oggetti disponibili: {0} in uso {1}", _pool.NumIdle, _pool.NumActive);
23:
24: Console.WriteLine("Rilascio due oggetti");
25: _pool.ReturnObject(_bigobj1);
26: _pool.ReturnObject(_bigobj3);
27:
28: Console.WriteLine("Oggetti disponibili: {0} in uso {1}", _pool.NumIdle, _pool.NumActive);
29:
30: Console.WriteLine("Richiedo altri tre oggetti");
31: BigObject _bigobj4 = _pool.BorrowObject() as BigObject;
32: Console.WriteLine(_bigobj4.DoWork());
33: BigObject _bigobj5 = _pool.BorrowObject() as BigObject;
34: Console.WriteLine(_bigobj5.DoWork());
35: BigObject _bigobj6 = _pool.BorrowObject() as BigObject;
36: Console.WriteLine(_bigobj6.DoWork());
37:
38: Console.WriteLine("Oggetti disponibili: {0} in uso {1}", _pool.NumIdle, _pool.NumActive);
39:
40: Console.WriteLine("Rilascio tutti gli oggetti.");
41: _pool.ReturnObject(_bigobj2);
42: _pool.ReturnObject(_bigobj4);
43: _pool.ReturnObject(_bigobj5);
44: _pool.ReturnObject(_bigobj6);
45:
46: Console.WriteLine("Oggetti disponibili: {0} in uso {1}", _pool.NumIdle, _pool.NumActive);
47:
48: Console.WriteLine("Tempo di utilizzo di 6 oggetti {0} secondi.", DateTime.Now.Subtract(_time).Seconds);
49:
50: Console.Read();
51: }
52: }
53: }