多线程总结(代码)

来源:互联网 发布:淘宝cpu散片哪家好 编辑:程序博客网 时间:2024/06/07 00:26

(1)[NSThread detachNewThreadSelector:@selector(createTableview) toTarget:self withObject:nil];


(2)[self performSelectorInBackground:@selector(createTableview) withObject:nil];


(3)    

    NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(createTableview) object:nil];

    [thread setName:@"HelloThread"];

    [thread setStackSize:4 * 1024];//提供4KB的整数倍

    [thread setThreadPriority:1.0f];//优先级配置,01不等的浮点数,分别表示CPU在空闲时分配资源给线程执行任务的优先度,0最小,1最大.

    [thread start];


(4)   

    NSOperation   (线程队列)控制并发数

    NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(createTableview) object:nil];

    [operation start];//单独建立它在主线程


(5)  

    //GCD大中央调度中心

    dispatch_queue_t main = dispatch_get_main_queue();//主队列,串行队列一个

    dispatch_async(main, ^{

        [self createTableview];

    });

0 0
原创粉丝点击