Three methods for creating multithreading in iOS and three methods for creating multithreading in ios
(1) // create a thread using the NSObject method </strong> </span> // (this method automatically opens up a background thread, parameter 1: the method executed in this background thread. Parameter 2: used to pass the parameter) [self defined mselectorinbackground: @ selector (banZhuanPlus) withObject: nil]; (2) // create a thread through NSThread (parameter 1: Method executor; parameter 2: method executed in the thread; parameter 3: used to pass Parameters) // Step 1: create thread NSThread * thread = [[NSThread alloc] initWithTarget: self selector: @ selector (banZhuanPlus) object: nil]; // Step 2: Execute [thread start]; [thread release]; (3) // NSOperation is an operation unit used to execute methods. It is an abstract class and must be subclass or use a subclass created by the system (NSInvocationOperation or NSBlockOperation) // NSOperation is the smallest operating unit; it can be executed only once; // NSInvocationOperation Step 1: Create NSInvocationOperation * invocation = [[NSInvocationOperation alloc] invocation: self selector: @ selector (banZhuanPlus) object: nil]; // Step 2: (do not add to the queue if not set) execute // [invocation start] in the main thread; // NSBlockOperation Step 1: create NSBlockOperation * block = [NSBlockOperation blockOperationWithBlock: ^ {[self banZhuanPlus];}]; // Step 2: Execute (executed in the main thread) // [block start]; // if it is added to the queue, do not start it. // This queue will automatically create an auxiliary thread for us. // In this queue, only NSOperation and subclass objects can be added; NSOperationQueue * queue = [[NSOperationQueue alloc] init]; [queue setMaxConcurrentOperationCount: 2]; // sets the maximum number of parallel rows; [queue addOperation: block]; // The operation queue will be executed as long as it is added to the queue; [queue addOperation: invocation]; // queue: first-in-first-out // Stack: advanced post-release // The serial and parallel tasks involved in the queue // serial: Only one task can be executed at a time // parallel: multiple tasks can be executed at a time (during full-disk replication, note that none of the annotations are integrated)
How to implement multiple threads in iOS
You asked the wrong question ~~ IOS is Object-C, not JAVA
How to Create Multithreading
The first method inherits the Thread, and the second method implements Runnable.
Public Class Threadone extends Thread {
Public void run () {// your implementation code}
}
Public class Threadtwo implements Runnable {
Public void run () {// your implementation code}
}
These two methods are called:
Public class {
Public static void main (String [] args ){
// The first call Method
Threadone one = new Threadone ();
One. start ();
// Method 2
Theadtwo two = new Threadtwo ();
Thread thread = new Thread (two );
Thread. start ();
}
}