****

#import "HMViewController.h"

@interface HMViewController ()

@end

@implementation HMViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)download:(NSString *)url
{
NSLog(@"下载东西---%@---%@", url, [NSThread currentThread]);
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self createThread3];
} /**
* 创建线程的方式3
*/
- (void)createThread3
{
// 这2个不会创建线程,在当前线程中执行
// [self performSelector:@selector(download:) withObject:@"http://c.gif"];
// [self download:@"http://c.gif"]; [self performSelectorInBackground:@selector(download:) withObject:@"http://c.gif"];
} /**
* 创建线程的方式2
*/
- (void)createThread2
{
[NSThread detachNewThreadSelector:@selector(download:) toTarget:self withObject:@"http://a.jpg"];
} /**
* 创建线程的方式1
*/
- (void)createThread1
{
// 创建线程
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(download:) object:@"http://b.png"];
thread.name = @"下载线程"; // 启动线程(调用self的download方法)
[thread start];
} @end

IOS第一天多线程-02NSThread基本使用的更多相关文章

  1. IOS第一天多线程-05GCD队列的使用

    ************** // // HMViewController.m // 08-GCD02-队列的使用(了解) // // Created by apple on 14-9-15. // ...

  2. IOS第一天多线程-04GCD通信

    **** #define HMGlobalQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) #define HMM ...

  3. IOS第一天多线程-03线程间通信

    **** #import "HMViewController.h" @interface HMViewController () @property (weak, nonatomi ...

  4. IOS第一天多线程-01pthread

    *** #import "HMViewController.h" #import <pthread.h> @interface HMViewController () ...

  5. iOS开发-多线程编程技术(Thread、Cocoa operations、GCD)

    简介 在软件开发中,多线程编程技术被广泛应用,相信多线程任务对我们来说已经不再陌生了.有了多线程技术,我们可以同做多个事情,而不是一个一个任务地进行.比如:前端和后台作交互.大任务(需要耗费一定的时间 ...

  6. ios开发之多线程---GCD

    一:基本概念 1:进程:正在运行的程序为进程. 2:线程:每个进程要想执行任务必须得有线程,进程中任务的执行都是在线程中. 3:线程的串行:一条线程里任务的执行都是串行的,假如有一个进程开辟了一条线程 ...

  7. 大厂常问iOS面试题--多线程篇

    1.进程与线程 进程: 1.进程是一个具有一定独立功能的程序关于某次数据集合的一次运行活动,它是操作系统分配资源的基本单元. 2.进程是指在系统中正在运行的一个应用程序,就是一段程序的执行过程,我们可 ...

  8. iOS开发之多线程技术(NSThread、OperationQueue、GCD)

    在前面的博客中如果用到了异步请求的话,也是用到的第三方的东西,没有正儿八经的用过iOS中多线程的东西.其实多线程的东西还是蛮重要的,如果对于之前学过操作系统的小伙伴来说,理解多线程的东西还是比较容易的 ...

  9. iOS开发之多线程技术

    本篇争取一篇讲清讲透,依然将通过四大方面清晰的对iOS开发中多线程的用法进行详尽的讲解: 一.什么是多线程 1)多线程执行原理 2)线程与进程 3)多线程的优缺点 二.我们为什么要用多线程编程技术 三 ...

随机推荐

  1. SU Demo之01MakingData--02MultiShot

  2. Scau 10327 Biggest Square

    时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description You are given a M*M cloth wi ...

  3. sql 循环某段时间的每一天

    create table #t1( 日期 datetime) declare @stime datetime;declare @etime datetime set @stime ='2015-01- ...

  4. http://www.cnblogs.com/summers/p/3225375.html

    http://www.cnblogs.com/summers/p/3225375.html

  5. zookeeper定时清理log

    在zookeeper的目录下新建一个脚本,内容如下(zookeeper bin下面也有zkCleanup.sh脚本,原理一样,都是调用java类) shell_dir=$(cd ")&quo ...

  6. Java web项目在linux环境下自动编译和部署脚本

    自动编译脚本 build.sh, 放置在项目根目录下. #!/bin/bash # check args # init path CURRPATH=`pwd` LIBDIR="$CURRPA ...

  7. mybatis 查询缓存问题

    <settings> <setting name="localCacheScope" value="STATEMENT" /> < ...

  8. 移动端H5页面之iphone6的适配(转)

    iphone6 及 iphone 6 plus 已经出来一段时间了.很多移动端网站,以前写死body 为320px的,现在估计也忙着做适配了. 大屏幕手机其实一直有,只是以前大家没怎么重视,移动端的H ...

  9. 【BZOJ】3211: 花神游历各国

    题意 \(n\)个点,第\(i\)个点值为\(a_i\).\(m\)个询问,每次询问\([l, r]\)内的和或者将\([l, r]\)的每个值改为自己的算术平方根.(\(n \le 100000, ...

  10. 深入浅出 - Android系统移植与平台开发(二) - 准备Android开发环境

    作者:唐老师,华清远见嵌入式学院讲师. 编译Android源码 关于android系统的编译,Android的官方网站上也给出了详细的说明.http://source.android.com/sour ...