19.同一线程加锁是没有效果的,多线程加锁才能起作用
2020-06-20 本文已影响0人
枫之叶_小乙哥
同一线程加锁是没有效果的,多线程加锁才能起作用
dispatch_async(dispatch_get_global_queue(0, 0), ^{
@synchronized (kFeedBackLock) {
if ([bodyDict containsObjectForKey:@"conversineType"] && [bodyDict containsObjectForKey:@"ackId"]) {
NSInteger type = [bodyDict[@"conversineType"] integerValue];
// NSUserDefaults 线程安全 保存信息, 每隔30s向后台发送回执
if (type == NFConversineTypePrivite) { // 私聊
[self saveFeedBackListWithBodyDict:bodyDict chatKey:kSingleChatKey];
} else if (type == NFConversineTypeGroup) { // 群聊
[self saveFeedBackListWithBodyDict:bodyDict chatKey:kGroupChatKey];
} else if (type == NFConversineTypeSystem) { // 系统消息
NSLog(@"信息:线程: %@", [NSThread currentThread]);
NSLog(@"信息:bodyDict: %@", bodyDict);
[self saveFeedBackListWithBodyDict:bodyDict chatKey:kSystemChatKey];
}
}
}
});