码迷,mamicode.com
首页 > 其他好文 > 详细

NSOperationQueue的maxConcurrentOperationCount属性

时间:2016-11-03 23:22:38      阅读:383      评论:0      收藏:0      [点我收藏+]

标签:时间间隔   imei   之间   时间   lock   ntop   soft   color   count   

代码:

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 2;

for (NSUInteger i = 1; i <= 10;  ++i) {
    [queue addOperationWithBlock:^{
        NSLog(@"Block %lu", i);
        [NSThread sleepForTimeInterval:1];
    }];
}

输出:

2016-11-03 22:20:37.508 maxConcurrentOperationCount[1196:26292] Block 1
2016-11-03 22:20:37.508 maxConcurrentOperationCount[1196:26295] Block 2
2016-11-03 22:20:38.512 maxConcurrentOperationCount[1196:26290] Block 3
2016-11-03 22:20:38.512 maxConcurrentOperationCount[1196:26295] Block 4
2016-11-03 22:20:39.517 maxConcurrentOperationCount[1196:26292] Block 5
2016-11-03 22:20:39.517 maxConcurrentOperationCount[1196:26290] Block 6
2016-11-03 22:20:40.523 maxConcurrentOperationCount[1196:26290] Block 8
2016-11-03 22:20:40.523 maxConcurrentOperationCount[1196:26295] Block 7
2016-11-03 22:20:41.525 maxConcurrentOperationCount[1196:26290] Block 9
2016-11-03 22:20:41.525 maxConcurrentOperationCount[1196:26292] Block 10

备注:

请注意每两行输出之间的时间间隔

NSOperationQueue的maxConcurrentOperationCount属性

标签:时间间隔   imei   之间   时间   lock   ntop   soft   color   count   

原文地址:http://www.cnblogs.com/loftyspirit/p/6028522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!