首页 > 编程语言 > 详细

多线程知识点总结 -NSThread4

时间:2016-08-05 06:31:04      阅读:150      评论:0      收藏:0      [点我收藏+]

NSThread

 三种创建方式

NSThread的对象方法
- (void)threadDemo1 {
    NSLog(@"before %@", [NSThread currentThread]);

    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(longOperation:) object:@"THREAD"];

    [thread start];

    NSLog(@"after %@", [NSThread currentThread]);
}
小结:在start方法执行完毕后,会在另一个线程执longOperation:方法

 NSThread的类方法
- (void)threadDemo2 {
    NSLog(@"before %@", [NSThread currentThread]);

    [NSThread detachNewThreadSelector:@selector(longOperation:) toTarget:self withObject:@"DETACH"];

    NSLog(@"after %@", [NSThread currentThread]);
}
小结:detachNewThreadSelector:类方法不需要启动;会自动创建线程并执行@selector方法
NSThread的类方法
- (void)threadDemo3 {
    NSLog(@"before %@", [NSThread currentThread]);

    [self performSelectorInBackground:@selector(longOperation:) withObject:@"PERFORM"];

    NSLog(@"after %@", [NSThread currentThread]);
}
小结:这是NSObject的分类方法,会在后台自动执行@selector方法;




 




 

多线程知识点总结 -NSThread4

原文:http://www.cnblogs.com/bixiangbei/p/5739061.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!