public class TestController : Controller { [ThreadStatic] static ThreadInfo obj; [HttpGet] public string Index() { return "123456"; } [HttpGet] public string bbb() { bool bnew = obj == null; if (bnew) { obj = new ThreadInfo(); obj.id = Thread.CurrentThread.ManagedThreadId.ToString(); obj.name = "controller hash="+this.GetHashCode(); } return bnew+"______class info{ hash:"+this.GetHashCode().ToString() +",thread id:"+Thread.CurrentThread.ManagedThreadId.ToString() +",_________"+obj.ToString(); } } class ThreadInfo { public String id; public String name; public override string ToString() { return "threadinfo{id:"+id+",name:"+name+",thread obj hash:"+GetHashCode().ToString(); } } //True______class info{ hash:26130175,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225 //False______class info{ hash:23697479,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225 //True______class info{ hash:55575390,thread id:74,_________threadinfo{id:74,name:controller hash=55575390,thread obj hash:18085517 //False______class info{ hash:7922750,thread id:74,_________threadinfo{id:74,name:controller hash=55575390,thread obj hash:18085517 //False______class info{ hash:26960933,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225 //False______class info{ hash:64947243,thread id:67,_________threadinfo{id:67,name:controller hash=26130175,thread obj hash:19998225
1.每次请求都会生成一个controller实例 (这个和java-spring里面默认的controller模式有区别)
2.请求会从线程池中取线程来处理
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。