示例#1
0
            public void CleanupPool()
            {
                lock (_syncRoot)
                {
                    CheckDisposedImpl();

                    var now       = GetTicks();
                    var available = _available.ToArray();
                    if (available.Count() <= _connectionString.MinPoolSize)
                    {
                        return;
                    }
                    var keep      = available.Where(x => ConnectionPoolLifetimeHelper.IsAlive(_connectionString.ConnectionLifeTime, x.Created, now)).ToArray();
                    var keepCount = keep.Count();
                    if (keepCount < _connectionString.MinPoolSize)
                    {
                        keep = keep.Concat(available.Except(keep).OrderByDescending(x => x.Created).Take(_connectionString.MinPoolSize - keepCount)).ToArray();
                    }
                    var release = available.Except(keep).ToArray();
                    release.AsParallel().ForAll(x => x.Dispose());
                    _available = new Stack <Item>(keep);
                }
            }
示例#2
0
            public void PrunePool()
            {
                lock (_syncRoot)
                {
                    CheckDisposedImpl();

                    var now       = GetTicks();
                    var available = _available.ToList();
                    if (available.Count <= _connectionString.MinPoolSize)
                    {
                        return;
                    }
                    var keep      = available.Where(x => ConnectionPoolLifetimeHelper.IsAlive(_connectionString.ConnectionLifetime, x.Created, now)).ToList();
                    var keepCount = keep.Count;
                    if (keepCount < _connectionString.MinPoolSize)
                    {
                        keep = keep.Concat(available.Except(keep).OrderByDescending(x => x.Created).Take(_connectionString.MinPoolSize - keepCount)).ToList();
                    }
                    var release = available.Except(keep).ToList();
                    Parallel.ForEach(release, x => x.Release(new AsyncWrappingCommonArgs(false)).GetAwaiter().GetResult());
                    _available = new Stack <Item>(keep);
                }
            }