<span style= "FONT-SIZE:18PX;" ><strong> (1)//create thread by NSObject method </strong></span> //(this method will automatically open a background thread, parameter 1: The method executed in this background thread, Parameter 2: for passing parameters) [self performselectorinbackground: @selector (Banzhuanplus) Withobject:nil];
(2)//Create a thread through Nsthread (parameter 1: The performer of the method; Parameter 2: The method executed in the thread; parameter 3: Used to pass parameters)
First step: Create a thread
Nsthread *thread = [[Nsthread alloc] initwithtarget:self selector: @selector (banzhuanplus) Object:nil];
Step Two: Execute
[Thread start];
[Thread release];
(3)//nsoperation is an operation unit, used to execute methods, is an abstract class, must be sub-class or use the system to create a good subclass (Nsinvocationoperation or nsblockoperation)
The nsoperation is the smallest operating unit and can only be executed once;
Nsinvocationoperation First step: Create
Nsinvocationoperation *invocation = [[Nsinvocationoperation alloc] initwithtarget:self selector: @selector ( Banzhuanplus) Object:nil];
Second step: (Do not set the words are not added to the queue) in the main thread to execute
[Invocation start];
Nsblockoperation First step: Create
Nsblockoperation *block = [Nsblockoperation blockoperationwithblock:^{
[Self banzhuanplus];
}];
Step Two: Execute (execute in main thread)
[Block start];//If added to the queue, don't start.
This queue will automatically help us create a secondary thread.
This queue can only add nsoperation and sub-class objects;
Nsoperationqueue *queue = [[Nsoperationqueue alloc] init];
[Queue setmaxconcurrentoperationcount:2];//Sets the maximum number of parallel;
[Queue addoperation:block];//is executed as long as the operation queue is added to the queue;
[Queue addoperation:invocation];
Queue: FIFO
Stack: Advanced back out
The queue involves serial and parallel
Serial: Only one task can be performed at a time
Parallel: Multiple tasks can be performed at one time
(When copying the whole piece, note that there is no annotation in one)
Three ways to create multi-threaded IOS