Nsoperation is a base class (abstract class (such as NSObject) that cannot be used directly by a subclass that must use it, which is operated by default on the current thread
Often used in conjunction with Nsoperationqueue (thread queue), which automatically opens up threads for operation when used with thread queues, without manual manipulation (* * * * *). If you only use nsoperation alone you must enable it manually
The Nsoperation system provides two sub-classes of nsinvocationoperation,nsblockoperation.
Single use operation he is synchronous execution
Nsblockoperation the number of operands is greater than 1 will open the thread to perform the operation
Initialization: Nsinvocationoperation
When it is used alone, remember to use manual operation: [Invocation start];
Invocation Implementation Method:
-(void) Act: (ID) sender{
NSLog (@ "%@\n%@", [Nsthread Currentthread],sender);
, [Nsthread CurrentThread] is which thread
}
Initialize Nsblockoperation:
Add action
Nsblockoperation the number of operands greater than 1 will open the thread to perform the operation [Blockoperation addexecutionblock:^{[Self act:@ "add operation"];}];
Manual operation is also required for use alone:
[Blockoperation start];
Nsoperationqueue (thread queue) management thread (default will open thread to execute)
Do not manually start the thread (* * *)
Initialize Nsoperationqueue
Sets the maximum number of concurrent threads (up to several operations, simultaneous operations) for the thread queue, i.e. if Queque.maxconcurrentoperationcount = 0, then only the main thread is executing
Queque.maxconcurrentoperationcount = 2;
Add Action (no manual action required when adding an action)
[Queque addoperation:invocation]; (when invocation added to Queque, put the previous [invocation start]; Comment out)
Multi-threaded-2