我有一个WCF服务,并希望在 PerSession模式和并发模式下使用到多个,但在消费时我正在使用单线程获取新的服务实例。下面是测试结果。
每个会话/并发模式 - 多个 ==============队列名称:1111,For Service CallServ Instance Created:1,and Thread:19 Time:4/6/2012 4:01:55 PM ====== ======
==============队列名称:1111,For Service CallServ Instance Created:2,and Thread:19 Time:4/6/2012 4:01:59 PM === ===========
==============队列名称:1111,For Service CallServ Instance Created:3,and Thread:19 Time:4/6/2012 4:02:03 PM === ===========
==============队列名称:1111,For Service CallServ Instance Created:4,and Thread:19 Time:4/6/2012 4:02:07 PM === ===========
==============队列名称:1111,For Service CallServ Instance Created:5,and Thread:19 Time:4/6/2012 4:02:11 PM === ===========
PerCall / Concurrency Mode - 单
==============队列名称:10006,For Service CallServ Instance Created:1,and Thread:13 Time:4/6/2012 2:06:22 PM === ===========
==============队列名称:10006,For Service CallServ Instance Created:1,and Thread:13 Time:4/6/2012 2:06:26 PM === ===========
==============队列名称:10006,For Service CallServ Instance Created:1,and Thread:13 Time:4/6/2012 2:06:30 PM === ===========
==============队列名称:10006,For Service CallServ Instance Created:1,and Thread:13 Time:4/6/2012 2:06:34 PM === ===========
==============队列名称:10006,For Service CallServ Instance Created:1,and Thread:6 Time:4/6/2012 2:06:38 PM === ===========
PerCall并发模式 - 多个 ==============队列名称:10007,For Service CallServ Instance Created:1,and Thread:6 Time:4/6/2012 2:08:32 PM ====== ======
==============队列名称:10007,For Service CallServ Instance Created:1,and Thread:6 Time:4/6/2012 2:08:36 PM === ===========
==============队列名称:10007,For Service CallServ Instance Created:1,and Thread:6 Time:4/6/2012 2:08:40 PM === ===========
==============队列名称:10007,For Service CallServ Instance Created:1,and Thread:6 Time:4/6/2012 2:08:44 PM === ===========
==============队列名称:10007,For Service CallServ Instance Created:1,and Thread:6 Time:4/6/2012 2:08:48 PM === ===========
给我一个解决方案。
提前致谢。
答案 0 :(得分:1)
在PerCall实例化中,并发性不相关,因为每个消息都由新的服务实例处理。
在Session实例中,并发性是相关的。在多个并发的情况下,应该编写线程安全的代码。请分享您的代码。