首页 > 代码库 > NSOperationQueue的maxConcurrentOperationCount属性
NSOperationQueue的maxConcurrentOperationCount属性
代码:
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属性
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。