小网点也有大作为_小也有大作为

2022-11-03 17:09:45 浏览数 (1)

在namespace PetShop.OrderProcessor.Program 的代码中:

1

// 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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/181174.html原文链接:https://javaforall.cn

0 人点赞