コード例 #1
0
ファイル: ThreadPoolImpl.cs プロジェクト: luozhiping1987/api
        internal ThreadPoolImpl(int minPoolSize, int maxPoolSize)
        {
            // TODO: check is these defaults make any size

            // minimum 4
            _minPoolSize = minPoolSize > 0 ? minPoolSize : Math.Max(4, GetNumCores() - 1);

            // CLR has max 250 threads per core...

            if (maxPoolSize <= 0)
            {
                // min-max 20;
                var maxThreadsMultiplier = 4;
                maxPoolSize = (_minPoolSize + 1) * maxThreadsMultiplier;
            }

            if (maxPoolSize < minPoolSize)
            {
                maxPoolSize = minPoolSize;
            }

            var queue = new RunnableQueue(this);

            _threadPool = new ThreadPoolExecutor(_minPoolSize, maxPoolSize, 60L, TimeUnit.SECONDS, queue);

            // there could be some logic to automatic reduce the number of threads again if they are
            // not needed. For now, we have the MemoryPressure approach.
            // TODO: MemoryPressure should automatically be called when Android signals memory pressure,
            //       probalby best from Dot42.Internal.Application.
        }
コード例 #2
0
        /// <summary>
        /// Default ctor
        /// </summary>
        internal ThreadPoolScheduler(bool isIOScheduler)
        {
            lowMaxPoolSize  = Math.Max(1, numCores - 1);
            highMaxPoolSize = isIOScheduler ? lowMaxPoolSize * 2 : lowMaxPoolSize * 3;
            var queue = new RunnableQueue();

            threadPool     = new ThreadPoolExecutor(lowMaxPoolSize, lowMaxPoolSize, 60L, TimeUnit.SECONDS, queue);
            queue.Executor = threadPool;
        }