public void Stop(string exchangeName) { SubThread thd = this[exchangeName]; if (thd != null) { try { ZeroLog.LogInfo("consumer stop...."); thd.TogglePause(true); //TODO //线程销毁和重入 //thd.Interrupt(); } catch (Exception ex) { ZeroLog.LogInfo("consumer stop...." + ex.Message); } finally { } } }
public void Start(string exchangeName) { ZeroLog.LogInfo("consumer start...." + exchangeName); SubThread thd = this[exchangeName]; thd.TogglePause(false); thd.Start(); }
public void SubThreadControl() { foreach (var subthread in SubThreads) { if (subthread.Capacity == 0 && SubThreads.Count > 2) { SubThreads.Remove(subthread); } else if (subthread.Capacity >= subthread.Max_capacity * 7 / 10) { subthread.Capacity = subthread.Capacity / 2; SubThread subthread3 = new SubThread(); subthread3.Capacity = subthread.Capacity; SubThreads.Add(subthread3); } } }
public MainThread() { Thread thread1 = new Thread(new ThreadStart(RequestFunction)); thread1.Start(); Thread thread2 = new Thread(new ThreadStart(ResponseFunction)); thread2.Start(); SubThread subthread1 = new SubThread(); SubThread subthread2 = new SubThread(); SubThreads.Add(subthread1); SubThreads.Add(subthread2); SubThreadCreator = new Thread(new ThreadStart(SubThreadControl)); SubThreadCreator.Start(); }
public void Declare() { if (!this.inited) { ZeroLog.LogInfo("consumer inited...."); List <ZeroRoute> rules = XMLExchange.GetInstance().Configs; foreach (var config in rules) { SubThread processor = new SubThread(); processor.Config = config; processor.ExchangeName = config.ExchangeName; pools.Add(config.ExchangeName, processor); ZeroLog.LogInfo("consumer inited...." + config.ExchangeName); } this.inited = true; } }