大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
//
the transaction timeout should be long enough to handle all of orders in the batch
2
TimeSpan tsTimeout
=
TimeSpan.FromSeconds(Convert.ToDouble(transactionTimeout
*
batchSize));
3
4
Order order
=
new
Order();
5
while
(
true
)
{
6
7 // queue timeout variables
8 TimeSpan datetimeStarting = new TimeSpan(DateTime.Now.Ticks);
9 double elapsedTime = 0;
10
11 int processedItems = 0;
12
13 ArrayList queueOrders = new ArrayList();
14
15 //OrderInfo orderData = orderQueue.Receive(timeout);
16 using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, tsTimeout)) {
17 // Console.WriteLine(“begin.at:” + DateTime.Now.ToString());
18 // Receive the orders from the queue
19 for (int j = 0; j < batchSize; j++) {
20 // Console.WriteLine(“从消息队列中取数据.at:” + DateTime.Now.ToString());
21
22 try {
23 //only receive more queued orders if there is enough time
24 if ((elapsedTime + queueTimeout + transactionTimeout) < tsTimeout.TotalSeconds) {
25 //Console.WriteLine(string.Format(“从消息队列中取数据.at:{0},{1},{2},{3},{4}”, DateTime.Now.ToString(), elapsedTime, queueTimeout, transactionTimeout, tsTimeout.TotalSeconds));
26 queueOrders.Add(order.ReceiveFromQueue(queueTimeout));
27
28 }
29 else {
30 j = batchSize; // exit loop
31 }
32
33 //update elapsed time
34 elapsedTime = new TimeSpan(DateTime.Now.Ticks).TotalSeconds – datetimeStarting.TotalSeconds;
35 }
36 catch (TimeoutException) {
37
38 //exit loop because no more messages are waiting
39 j = batchSize;
40 //Console.WriteLine(“TimeoutException.at:” + DateTime.Now.ToString());
41 }
42 }
43 // Console.WriteLine(“从消息队列中取数据Over.at:” + DateTime.Now.ToString());
44
45 //process the queued orders
46 for (int k = 0; k < queueOrders.Count; k++) {
47 order.Insert((OrderInfo)queueOrders[k]);
48 processedItems++;
49 totalOrdersProcessed++;
50
51 }
52 // Console.WriteLine(“上传数据.at:” + DateTime.Now.ToString());
53
54 //batch complete or MSMQ receive timed out
55 ts.Complete();
56 // Console.WriteLine(“Over.at:” + DateTime.Now.ToString());
57 }
58
59 Console.WriteLine(“(Thread Id “ + Thread.CurrentThread.ManagedThreadId + “) batch finished, “ + processedItems + “ items, in “ + elapsedTime.ToString() + “ seconds.at:“+DateTime.Now.ToString());
60 }
问题在于第2行:
TimeSpan tsTimeout
=
TimeSpan.FromSeconds(Convert.ToDouble(transactionTimeout
*
batchSize));
如果在配置文件里设置
batchSize=1,那么
tsTimeout
=
transactionTimeout
所以在24行。
if
((elapsedTime
+
queueTimeout
+
transactionTimeout)
<
tsTimeout.TotalSeconds)
,这个永远为False.除非
queueTimeout为负数
转载于:https://www.cnblogs.com/zhpeng/archive/2008/04/17/1157436.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/181174.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...