The first rule to insert a database: The next action after the last operation is executed if the data in the database operation is relatively large, the main thread will be stuck (running particularly slow) solution:to add a child thread to a database Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0), ^{
for (int i = 0; i <; i++) {
[[Fmdbmanager sharedintance] inserttablenamewithtablename:@ "Dota" name:@ "Lasy" gender:@ "F" age:@ "a" Image: Uiimagepngrepresentation ([UIImage imagenamed:@ "2.jpg"]) myid:@ "5"]; } }); However, when a child thread is added, it can cause the program to Crash the solution if it is asynchronous: The block queue operation code is as follows:#注意: If Nsoperationqueue is local, each execution will have a different block queue in the execution of the Nsoperationqueue object that is added as a propertyself. Queue = [[nsoperationqueue alloc] init]; nsblockoperation *block1 = [nsblockoperation blockoperationwithblock:^{ for (int 0 < 1000 [[fmdbmanager sharedintance] Inserttablenamewithtablename:@ "Dota"Name:@ "Lasy"Gender:@ "Woman"Age:@ "12"Image:Uiimagepngrepresentationuiimage Imagenamed:@ "2.jpg" ]) myid@ "2" ];&NBSP; } }];nsblockoperation *block2 = [nsblockoperation blockoperationwithblock: ^{ for (int 0 < 1000 [[FmdbmanagerSharedintance]Inserttablenamewithtablename:@ "Dota"Name:@ "Sony" Gender:@ "Male"Age:@ "22"Image:Uiimagepngrepresentation([UIImageImagenamed: @ "3.jpg" ]) myid@ "1" "; } }]; [selfqueue Addoperation[self. Queue addoperation: Block2]; It feels like this can really solve the problem of multiple sub-threads in asynchronous operation, but in fact it will still be Crash at run time .even with FMDB third-partyThe Nsoperation object that adds the property is initialized in Viewdidload and sets his maximum number of concurrent executions code as follows:[self. Queue Setmaxconcurrentoperationcount:1]; so the problem is solved.
FMDB threading issues when working with large data