internal EndpointHostResolver(Instance instance) { _instance = instance; _protocol = instance.protocolSupport(); _preferIPv6 = instance.preferIPv6(); _thread = new HelperThread(this); updateObserver(); _thread.Start(Util.stringToThreadPriority( instance.initializationData().properties.getProperty("Ice.ThreadPriority"))); }
public ThreadPool(Instance instance, string prefix, int timeout) { Ice.Properties properties = instance.initializationData().properties; _instance = instance; _dispatcher = instance.initializationData().dispatcher; _destroyed = false; _prefix = prefix; _threadIndex = 0; _inUse = 0; _serialize = properties.getPropertyAsInt(_prefix + ".Serialize") > 0; _serverIdleTime = timeout; string programName = properties.getProperty("Ice.ProgramName"); if (programName.Length > 0) { _threadPrefix = programName + "-" + _prefix; } else { _threadPrefix = _prefix; } // // We use just one thread as the default. This is the fastest // possible setting, still allows one level of nesting, and // doesn't require to make the servants thread safe. // int size = properties.getPropertyAsIntWithDefault(_prefix + ".Size", 1); if (size < 1) { string s = _prefix + ".Size < 1; Size adjusted to 1"; _instance.initializationData().logger.warning(s); size = 1; } int sizeMax = properties.getPropertyAsIntWithDefault(_prefix + ".SizeMax", size); if (sizeMax < size) { string s = _prefix + ".SizeMax < " + _prefix + ".Size; SizeMax adjusted to Size (" + size + ")"; _instance.initializationData().logger.warning(s); sizeMax = size; } int sizeWarn = properties.getPropertyAsInt(_prefix + ".SizeWarn"); if (sizeWarn != 0 && sizeWarn < size) { string s = _prefix + ".SizeWarn < " + _prefix + ".Size; adjusted SizeWarn to Size (" + size + ")"; _instance.initializationData().logger.warning(s); sizeWarn = size; } else if (sizeWarn > sizeMax) { string s = _prefix + ".SizeWarn > " + _prefix + ".SizeMax; adjusted SizeWarn to SizeMax (" + sizeMax + ")"; _instance.initializationData().logger.warning(s); sizeWarn = sizeMax; } int threadIdleTime = properties.getPropertyAsIntWithDefault(_prefix + ".ThreadIdleTime", 60); if (threadIdleTime < 0) { string s = _prefix + ".ThreadIdleTime < 0; ThreadIdleTime adjusted to 0"; _instance.initializationData().logger.warning(s); threadIdleTime = 0; } _size = size; _sizeMax = sizeMax; _sizeWarn = sizeWarn; _threadIdleTime = threadIdleTime; int stackSize = properties.getPropertyAsInt(_prefix + ".StackSize"); if (stackSize < 0) { string s = _prefix + ".StackSize < 0; Size adjusted to OS default"; _instance.initializationData().logger.warning(s); stackSize = 0; } _stackSize = stackSize; _priority = properties.getProperty(_prefix + ".ThreadPriority").Length > 0 ? Util.stringToThreadPriority(properties.getProperty(_prefix + ".ThreadPriority")) : Util.stringToThreadPriority(properties.getProperty("Ice.ThreadPriority")); if (_instance.traceLevels().threadPool >= 1) { string s = "creating " + _prefix + ": Size = " + _size + ", SizeMax = " + _sizeMax + ", SizeWarn = " + _sizeWarn; _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s); } _workItems = new Queue <ThreadPoolWorkItem>(); try { _threads = new List <WorkerThread>(); for (int i = 0; i < _size; ++i) { WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++); thread.start(_priority); _threads.Add(thread); } } catch (System.Exception ex) { string s = "cannot create thread for `" + _prefix + "':\n" + ex; _instance.initializationData().logger.error(s); destroy(); joinWithAllThreads(); throw; } }
public ThreadPool(Ice.Communicator communicator, string prefix, int timeout) { _communicator = communicator; _dispatcher = communicator.Dispatcher; _destroyed = false; _prefix = prefix; _threadIndex = 0; _inUse = 0; _serialize = _communicator.GetPropertyAsInt($"{_prefix}.Serialize") > 0; _serverIdleTime = timeout; string?programName = _communicator.GetProperty("Ice.ProgramName"); if (programName != null) { _threadPrefix = programName + "-" + _prefix; } else { _threadPrefix = _prefix; } // // We use just one thread as the default. This is the fastest // possible setting, still allows one level of nesting, and // doesn't require to make the servants thread safe. // int size = _communicator.GetPropertyAsInt($"{_prefix}.Size") ?? 1; if (size < 1) { string s = _prefix + ".Size < 1; Size adjusted to 1"; _communicator.Logger.warning(s); size = 1; } int sizeMax = _communicator.GetPropertyAsInt($"{_prefix}.SizeMax") ?? size; if (sizeMax < size) { _communicator.Logger.warning($"{_prefix}.SizeMax < {_prefix}.Size; SizeMax adjusted to Size ({size})"); sizeMax = size; } int sizeWarn = _communicator.GetPropertyAsInt($"{_prefix}.SizeWarn") ?? 0; if (sizeWarn != 0 && sizeWarn < size) { _communicator.Logger.warning( $"{_prefix}.SizeWarn < {_prefix}.Size; adjusted SizeWarn to Size ({size})"); sizeWarn = size; } else if (sizeWarn > sizeMax) { _communicator.Logger.warning( "${_prefix}.SizeWarn > {_prefix}.SizeMax; adjusted SizeWarn to SizeMax ({sizeMax})"); sizeWarn = sizeMax; } int threadIdleTime = _communicator.GetPropertyAsInt($"{_prefix}.ThreadIdleTime") ?? 60; if (threadIdleTime < 0) { _communicator.Logger.warning($"{_prefix}.ThreadIdleTime < 0; ThreadIdleTime adjusted to 0"); threadIdleTime = 0; } _size = size; _sizeMax = sizeMax; _sizeWarn = sizeWarn; _threadIdleTime = threadIdleTime; int stackSize = communicator.GetPropertyAsInt($"{_prefix }.StackSize") ?? 0; if (stackSize < 0) { _communicator.Logger.warning($"{_prefix}.StackSize < 0; Size adjusted to OS default"); stackSize = 0; } _stackSize = stackSize; _priority = Util.stringToThreadPriority(_communicator.GetProperty($"{_prefix}.ThreadPriority") ?? _communicator.GetProperty("Ice.ThreadPriority")); if (_communicator.traceLevels().threadPool >= 1) { _communicator.Logger.trace(_communicator.traceLevels().threadPoolCat, $"creating {_prefix}: Size = {_size}, SizeMax = {_sizeMax}, SizeWarn = {_sizeWarn}"); } _workItems = new Queue <ThreadPoolWorkItem>(); try { _threads = new List <WorkerThread>(); for (int i = 0; i < _size; ++i) { WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++); thread.start(_priority); _threads.Add(thread); } } catch (System.Exception ex) { string s = "cannot create thread for `" + _prefix + "':\n" + ex; _communicator.Logger.error(s); destroy(); joinWithAllThreads(); throw; } }