本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址(2013年12月29日更新版)

 

  1. iOS程序源代码下载链接:
    01.大任务.zip
    225.8 KB
  2. //
  3. //  ViewController.m
  4. //  01.大任务
  5. //
  6. //  Created by apple on 13-12-27.
  7. //  Copyright (c) 2013年itcast. All rights reserved.
  8. //
  9. #import"ViewController.h"
  10. @interfaceViewController()
  11. {
  12.     //全局的操作队列,由它统一控制所有的NSOperation的操作调度
  13.     NSOperationQueue        *_queue;
  14. }
  15. @property(weak,nonatomic)IBOutletUIImageView*imageView;
  16. @end
  17. @implementationViewController
  18. /**
  19.  无论使用哪种多线程技术都可以使用
  20.  [NSThread currentThread]跟踪查看当前执行所在的线程情况。
  21.  num = 1表示在主线程上执行的任务
  22.  
  23.  ================================================================
  24.  1. NSObject多线程技术
  25.  
  26.  1>使用performSelectorInBackground可以开启后台线程,执行selector选择器选择的方法
  27.  2>使用performSelectorOnMainThread可以重新回到主线程执行任务,通常用于后台线程更新界面UI时使用
  28.  3> [NSThread sleepForTimeInterval:1.0f];
  29.     让当前线程休眠,通常在程序开发中,用于模拟耗时操作,以便跟踪不同的并发执行情况!
  30.  
  31.     但是:在程序发布时,千万不要保留此方法!不要把测试中的代码交给客户,否则会造成不好的用户体验。
  32.  
  33.  提示:使用performSelectorInBackground也可以直接修改UI,但是强烈不建议使用。
  34.  
  35.  注意:在使用NSThread或者NSObject的线程方法时,一定要使用自动释放池,否则容易出现内存泄露。
  36.  
  37.  ================================================================
  38.  2. NSThread的多线程技术
  39.  
  40.  1>类方法直接开启后台线程,并执行选择器方法
  41.     detachNewThreadSelector
  42.  
  43.  2>成员方法,在实例化线程对象之后,需要使用start执行选择器方法
  44.     initWithTarget
  45.  
  46.  对于NSThread的简单使用,可以用NSObject的performSelectorInBackground替代
  47.  
  48.  同时,在NSThread调用的方法中,同样要使用autoreleasepool进行内存管理,否则容易出现内存泄露。
  49.  //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3494810.html
  50.  ================================================================
  51.  3. NSOperation,面向对象的多线程技术
  52.  
  53.  1>使用步骤:
  54.     1)实例化操作
  55.         a) NSInvocationOperation
  56.         b) NSBlockOperation
  57.     2)将操作添加到队列NSOperationQueue即可启动多线程执行
  58.  
  59.  2>更新UI使用主线程队列
  60.     [NSOpeationQueue mainQueue] addOperation ^{};
  61.  
  62.  3>操作队列的setMaxConcurrentOperationCount
  63.     可以设置同时并发的线程数量!
  64.  
  65.     提示:此功能仅有NSOperation有!
  66.  
  67.  4>使用addDependency可以设置任务的执行先后顺序,同时可以跨操作队列指定依赖关系
  68.  
  69.     提示:在指定依赖关系时,注意不要循环依赖,否则不工作。
  70.  //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3494810.html
  71.  ================================================================
  72.  4. GCD,C语言
  73.  
  74.  */
  75. - (void)viewDidLoad
  76. {
  77.     [superviewDidLoad];
  78.     
  79.     NSLog(@"%@", [NSThreadcurrentThread]);
  80.     
  81.     //实例化操作队列
  82.     _queue= [[NSOperationQueuealloc]init];
  83. }
  84. #pragma mark -操作
  85. //耗时操作演示
  86. - (void)bigDemo
  87. {
  88.     //自动释放池
  89.     //负责其他线程上的内存管理,在使用NSThread或者NSObject的线程方法时,一定要使用自动释放池
  90.     //否则容易出现内存泄露。
  91.     @autoreleasepool{
  92.         //    //模拟网络下载延时
  93.         //    for (NSInteger i = 0; i < 1000; i++) {
  94.         //        NSString *str = [NSString stringWithFormat:@"%d", i];
  95.         //
  96.         //        //提示:NSLog是非常耗时的操作!
  97.         //        NSLog(@"大任务-> %@", str);
  98.         //    }
  99.         
  100.         NSLog(@"%@", [NSThreadcurrentThread]);
  101.         //模拟网络下载延时,睡眠1秒,通常是在开发中测试使用。
  102.         [NSThreadsleepForTimeInterval:1.0f];
  103.         
  104.         //强烈不建议直接在后台线程更新界面UI!
  105.         //模拟获取到下载的图像
  106.         UIImage*image = [UIImageimageNamed:@"头像1"];
  107.         
  108.         //在主线程更新图像
  109.         //使用self调用updateImage方法在主线程更新图像
  110.         //    [self performSelectorOnMainThread:@selector(updateImage:) withObject:image waitUntilDone:YES];
  111.         
  112.         //使用imageView的setImage方法在主线程更新图像
  113.         [_imageViewperformSelectorOnMainThread:@selector(setImage:)withObject:imagewaitUntilDone:YES];
  114.         
  115.         // ....
  116.     }
  117. }
  118. #pragma mark -更新图像,模拟从网络上下载完图片后,更新界面的操作
  119. - (void)updateImage:(UIImage*)image
  120. {
  121.     NSLog(@"更新图像-> %@", [NSThreadcurrentThread]);
  122.     
  123.     _imageView.image= image;
  124. }
  125. #pragma mark - Actions
  126. - (IBAction)bigTask
  127. {
  128.     //本方法中的所有代码都是在主线程中执行的
  129.     // NSObject多线程技术
  130.     NSLog(@"执行前->%@", [NSThreadcurrentThread]);
  131.     
  132.     // performSelectorInBackground是将bigDemo的任务放在后台线程中执行
  133.     [selfperformSelectorInBackground:@selector(bigDemo)withObject:nil];
  134.     
  135.     NSLog(@"执行后->%@", [NSThreadcurrentThread]);
  136. //    [self bigDemo];
  137.     
  138.     NSLog(@"执行完毕");
  139. }
  140. - (IBAction)smallTask
  141. {
  142.     NSString*str =nil;
  143.     
  144.     for(NSIntegeri =0; i <50000; i++) {
  145.         str = [NSStringstringWithFormat:@"%d", i];
  146.     }
  147.     
  148.     NSLog(@"小任务-> %@", str);
  149. }
  150. #pragma mark NSThread演练
  151. - (IBAction)threadDemo
  152. {
  153.     //新建一个线程,调用@selector方法
  154. //    [NSThread detachNewThreadSelector:@selector(bigDemo) toTarget:self withObject:nil];
  155.     
  156.     //成员方法
  157.     NSThread*thread = [[NSThreadalloc]initWithTarget:selfselector:@selector(bigDemo)object:nil];
  158.     
  159.     //启动start线程
  160.     [threadstart];
  161. }
  162. #pragma mark - NSOperation演练
  163. - (void)opAction
  164. {
  165.     NSLog(@"%@", [NSThreadcurrentThread]);
  166.     
  167.     //模拟延时
  168.     [NSThreadsleepForTimeInterval:1.0f];
  169.     
  170.     //模拟获取到图像
  171.     UIImage*image = [UIImageimageNamed:@"头像1"];
  172.     
  173.     //设置图像,在主线程队列中设置
  174.     [[NSOperationQueuemainQueue]addOperationWithBlock:^{
  175.         _imageView.image= image;
  176.     }];
  177. }
  178. #pragma mark invocation
  179. - (IBAction)operationDemo1
  180. {
  181.     NSInvocationOperation*op1 = [[NSInvocationOperationalloc]initWithTarget:selfselector:@selector(opAction)object:nil];
  182.     
  183.     //如果使用start,会在当前线程启动操作
  184. //    [op1 start];
  185.     
  186.     // 1.一旦将操作添加到操作队列,操作就会启动
  187.     [_queueaddOperation:op1];
  188. }
  189. #pragma mark blockOperation
  190. - (IBAction)operationDemo2
  191. {
  192.     //用block的最大好处,可以将一组相关的操作,顺序写在一起,便于调试以及代码编写
  193.     [_queueaddOperationWithBlock:^{
  194.         NSLog(@"%@", [NSThreadcurrentThread]);
  195.         
  196.         //模拟延时
  197.         [NSThreadsleepForTimeInterval:1.0f];
  198.         
  199.         //模拟获取到图像
  200.         UIImage*image = [UIImageimageNamed:@"头像1"];
  201.         
  202.         //设置图像,在主线程队列中设置
  203.         [[NSOperationQueuemainQueue]addOperationWithBlock:^{
  204.             _imageView.image= image;
  205.         }];
  206.     }];
  207. }
  208. #pragma mark模仿下载网络图像
  209. - (IBAction)operationDemo3:(id)sender
  210. {
  211.     // 1.下载
  212.     NSBlockOperation*op1 = [NSBlockOperationblockOperationWithBlock:^{
  213.         NSLog(@"下载%@", [NSThreadcurrentThread]);
  214.     }];
  215.     // 2.滤镜
  216.     NSBlockOperation*op2 = [NSBlockOperationblockOperationWithBlock:^{
  217.         NSLog(@"滤镜%@", [NSThreadcurrentThread]);
  218.     }];
  219.     // 3.显示
  220.     NSBlockOperation*op3 = [NSBlockOperationblockOperationWithBlock:^{
  221.         NSLog(@"更新UI %@", [NSThreadcurrentThread]);
  222.     }];
  223.     //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3494810.html
  224.     //添加操作之间的依赖关系,所谓“依赖”关系,就是等待前一个任务完成后,后一个任务才能启动
  225.     //依赖关系可以跨线程队列实现
  226.     //提示:在指定依赖关系时,注意不要循环依赖,否则不工作。
  227.     [op2addDependency:op1];
  228.     [op3addDependency:op2];
  229. //    [op1 addDependency:op3];
  230.     
  231.     [_queueaddOperation:op1];
  232.     [_queueaddOperation:op2];
  233.     [[NSOperationQueuemainQueue]addOperation:op3];
  234. }
  235. #pragma mark限制线程数量
  236. - (IBAction)operationDemo4
  237. {
  238.     //控制同时最大并发的线程数量
  239.     [_queuesetMaxConcurrentOperationCount:2];
  240.     
  241.     for(NSIntegeri =0; i <200; i++) {
  242.         NSBlockOperation*op = [NSBlockOperationblockOperationWithBlock:^{
  243.             NSLog(@"%@", [NSThreadcurrentThread]);
  244.         }];
  245.         
  246.         [_queueaddOperation:op];
  247.     }
  248. }
  249. #pragma mark - GCD演练
  250. - (IBAction)gcdDemo1
  251. {
  252.     /**
  253.      GCD就是为了在“多核”上使用多线程技术
  254.      
  255.      1>要使用GCD,所有的方法都是dispatch开头的
  256.      2>名词解释
  257.         global 全局
  258.         queue  队列
  259.         async  异步
  260.         sync   同步
  261.      
  262.      3>要执行异步的任务,就在全局队列中执行即可
  263.         dispatch_async异步执行控制不住先后顺序
  264.      
  265.      4>关于GCD的队列
  266.         全局队列    dispatch_get_global_queue
  267.             参数:优先级DISPATCH_QUEUE_PRIORITY_DEFAULT
  268.                  始终是0
  269.         串行队列
  270.         主队列
  271.      
  272.      5>异步和同步于方法名无关,与运行所在的队列有关!
  273.         提示:要熟悉队列于同步、异步的运行节奏,一定需要自己编写代码测试!
  274.      
  275.         同步主要用来控制方法的被调用的顺序
  276.      */
  277.     // 1.队列
  278.     dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
  279.     
  280.     // 2.将任务异步(并发)执行
  281.     dispatch_async(queue, ^{
  282.         NSLog(@"a->%@", [NSThreadcurrentThread]);
  283.     });
  284.     dispatch_async(queue, ^{
  285.         NSLog(@"b->%@", [NSThreadcurrentThread]);
  286.     });
  287.     
  288.     dispatch_async(dispatch_get_main_queue(), ^{
  289.         NSLog(@"main - > %@", [NSThreadcurrentThread]);
  290.     });
  291. }
  292. @end
 

连续点击两次大任务按钮,运行结果

执行前-><NSThread: 0x764bcb0>{name = (null), num = 1}
执行后-><NSThread: 0x764bcb0>{name = (null), num = 1}
执行完毕
bigDemo<NSThread: 0x768d8f0>{name = (null), num = 3}
执行前-><NSThread: 0x764bcb0>{name = (null), num = 1}
bigDemo<NSThread: 0x755c8d0>{name = (null), num = 4}
执行后-><NSThread: 0x764bcb0>{name = (null), num = 1}
执行完毕

结论

performSelectorInBackground:withObject:该方法会使方法在后台运行,并负责为其分配线程号,一个线程3结束后,不会被回收.再次调用performSelectorInBackground:withObject:会分配4而非3

连续点击NSThread,运行结果

2013-12-27 19:06:01.311 1226-01-大任务[4742:51b] bigDemo<NSThread: 0x753d5d0>{name = (null), num = 3}
2013-12-27 19:06:06.266 1226-01-
大任务[4742:440b] bigDemo<NSThread: 0x753f1f0>{name = (null), num = 4}
2013-12-27 19:06:07.060 1226-01-
大任务[4742:4503] bigDemo<NSThread: 0x7540cb0>{name = (null), num = 5}
2013-12-27 19:06:07.659 1226-01-
大任务[4742:440f] bigDemo<NSThread: 0x753d9f0>{name = (null), num = 6}
2013-12-27 19:06:08.318 1226-01-
大任务[4742:4507] bigDemo<NSThread: 0x7540cb0>{name = (null), num = 7}

结论

initWithTarget:selector:object:方法能为方法分配线程

连续点击NSOperation按钮,运行结果

2013-12-27 19:24:16.153 1226-01-大任务[4858:1703] <NSThread: 0x7686610>{name = (null), num = 3}
2013-12-27 19:24:18.755 1226-01-
大任务[4858:4203] <NSThread: 0x768acf0>{name = (null), num = 4}
2013-12-27 19:24:19.245 1226-01-
大任务[4858:1103] <NSThread: 0x768aa40>{name = (null), num = 5}
2013-12-27 19:24:19.724 1226-01-
大任务[4858:1703] <NSThread: 0x7686610>{name = (null), num = 3}
2013-12-27 19:24:20.205 1226-01-
大任务[4858:4703] <NSThread: 0x768b7e0>{name = (null), num = 6}

结论

 addOperation:方法能为方法分配线程

 

连续点击NSBlockOperation按钮,运行结果

2013-12-27 19:24:16.153 1226-01-大任务[4858:1703] <NSThread: 0x7686610>{name = (null), num = 3}
2013-12-27 19:24:18.755 1226-01-
大任务[4858:4203] <NSThread: 0x768acf0>{name = (null), num = 4}
2013-12-27 19:24:19.245 1226-01-
大任务[4858:1103] <NSThread: 0x768aa40>{name = (null), num = 5}
2013-12-27 19:24:19.724 1226-01-
大任务[4858:1703] <NSThread: 0x7686610>{name = (null), num = 3}
2013-12-27 19:24:20.205 1226-01-
大任务[4858:4703] <NSThread: 0x768b7e0>{name = (null), num = 6}

结论

operationDemo1方法与operationDemo2方法效果一致

    //用block的最大好处,可以将一组相关的操作,顺序写在一起,便于调试以及代码编写

限制并发线程数,运行结果

黄色部分是时间,结果发现:相同的时间只可能出现两次.

2013-12-27 20:00:58.088 1226-01-大任务[5127:1703] <NSThread: 0x754ad60>{name = (null), num = 4}
2013-12-27 20:00:58.088 1226-01-
大任务[5127:1103] <NSThread: 0x7667740>{name = (null), num = 3}
2013-12-27 20:00:58.092 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.093 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.096 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.096 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.099 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.100 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.101 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.102 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.105 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.106 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.107 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}
2013-12-27 20:00:58.107 1226-01-
大任务[5127:4107] <NSThread: 0x7530f50>{name = (null), num = 6}
2013-12-27 20:00:58.125 1226-01-
大任务[5127:1703] <NSThread: 0x754ad60>{name = (null), num = 4}
2013-12-27 20:00:58.126 1226-01-
大任务[5127:4107] <NSThread: 0x7530f50>{name = (null), num = 6}
2013-12-27 20:00:58.129 1226-01-
大任务[5127:1103] <NSThread: 0x7667740>{name = (null), num = 3}
2013-12-27 20:00:58.129 1226-01-
大任务[5127:1703] <NSThread: 0x754ad60>{name = (null), num = 4}
2013-12-27 20:00:58.132 1226-01-
大任务[5127:517] <NSThread: 0x752def0>{name = (null), num = 5}


结论

setMaxConcurrentOperationCount 方法能控制同时最大并发的线程数量

运行两次程序,并在每次运行时连续点击gcd按钮三次,运行结果

——————————————————— <第⓵次运行gcd>———————————————————————

——————————————————— <第⓵点击gcd按钮>———————————————————————
2013-12-27 20:23:49.987 1226-01-大任务[5270:907] #########main - ><NSThread: 0x75652f0>{name = (null), num = 1}
2013-12-27 20:23:49.988 1226-01-大任务[5270:1103] ###########################-><NSThread: 0x75848f0>{name = (null), num = 3}
2013-12-27 20:23:49.987 1226-01-大任务[5270:1903] ###################-><NSThread: 0x76bfb20>{name = (null), num = 4}
——————————————————— <第⓶点击gcd按钮>———————————————————————
2013-12-27 20:23:54.336 1226-01-大任务[5270:907] #########main - ><NSThread: 0x75652f0>{name = (null), num = 1}
2013-12-27 20:23:54.337 1226-01-大任务[5270:1103] ###########################-><NSThread: 0x75848f0>{name = (null), num = 3}
2013-12-27 20:23:54.337 1226-01-大任务[5270:1103] ###################-><NSThread: 0x75848f0>{name = (null), num = 3}
——————————————————— <第⓷点击gcd按钮>———————————————————————
2013-12-27 20:23:59.435 1226-01-大任务[5270:907] #########main - ><NSThread: 0x75652f0>{name = (null), num = 1}
2013-12-27 20:23:59.436 1226-01-大任务[5270:1103] ###########################-><NSThread: 0x75848f0>{name = (null), num = 3}
2013-12-27 20:23:59.437 1226-01-大任务[5270:1103] ###################-><NSThread: 0x75848f0>{name = (null), num = 3}

——————————————————— <第⓶次运行gcd>———————————————————————

——————————————————— <第⓵点击gcd按钮>———————————————————————
2013-12-27 20:24:49.950 1226-01-大任务[5288:907] #########main - ><NSThread: 0x764b3e0>{name = (null), num = 1}
2013-12-27 20:24:49.950 1226-01-大任务[5288:1a03] ###################-><NSThread: 0x76911d0>{name = (null), num = 4}
2013-12-27 20:24:49.949 1226-01-大任务[5288:1103] ###########################-><NSThread: 0x7687e20>{name = (null), num = 3}
——————————————————— <第⓶点击gcd按钮>———————————————————————
2013-12-27 20:24:53.798 1226-01-大任务[5288:907] #########main - ><NSThread: 0x764b3e0>{name = (null), num = 1}
2013-12-27 20:24:53.798 1226-01-大任务[5288:1a03] ###################-><NSThread: 0x76911d0>{name = (null), num = 4}
2013-12-27 20:24:53.798 1226-01-大任务[5288:1103] ###########################-><NSThread: 0x7687e20>{name = (null), num = 3}
——————————————————— <第⓷点击gcd按钮>———————————————————————
2013-12-27 20:24:55.320 1226-01-大任务[5288:907] #########main - ><NSThread: 0x764b3e0>{name = (null), num = 1}
2013-12-27 20:24:55.321 1226-01-大任务[5288:1a03] ###################-><NSThread: 0x76911d0>{name = (null), num = 4}
2013-12-27 20:24:55.321 1226-01-大任务[5288:1103] ###########################-><NSThread: 0x7687e20>{name = (null), num = 3}

结论

  1. 要执行异步的任务,就在全局队列dispatch_get_global_queue中执行即可
  2. dispatch_async异步执行控制不住先后顺序

 //转载请注明出处--本文永久链接:http://www.cnblogs.com/ChenYilong/p/3494810.html

https://www.evernote.com/shard/s227/sh/911b8ec7-498f-4c93-b180-6713e5e03931/382ccb2b15dd2630ddd9756e48fc1446

iOS多线程 iOS开发Demo(示例程序)源代码的更多相关文章

  1. 03.WebView演练-iOS开发Demo(示例程序)源代码

    技术博客http://www.cnblogs.com/ChenYilong/   新浪微博http://weibo.com/luohanchenyilong   //转载请注明出处--本文永久链接:h ...

  2. 代理设计模式iOS开发Demo(示例程序)源代码

        iOS程序源代码下载链接:03-代理设计模式.zip28.3 KB // main.m // //  main.m //  03-代理设计模式 // //  Created by apple ...

  3. 01-QQ 3-最终重构版 Demo示例程序源代码

      源代码下载链接:01-QQ 3.zip292.5 KB // QQAppDelegate.h Map // //  QQAppDelegate.h //  01-QQ // //  Created ...

  4. 01-modal Demo示例程序源代码

    源代码下载链接:01-modal.zip37.8 KB // MJAppDelegate.h // //  MJAppDelegate.h //  01-modal // //  Created by ...

  5. 02-更改窗口的根控制器 Demo示例程序源代码

      源代码下载链接:02-更改窗口的根控制器.zip18.0 KB // MJAppDelegate.h // //  MJAppDelegate.h //  02-更改窗口的根控制器 // //  ...

  6. 归档普通对象Demo示例程序源代码

    源代码下载链接:06-归档普通对象.zip34.2 KB // MJPerson.h // //  MJPerson.h //  06-归档普通对象 // //  Created by apple o ...

  7. 01-导航实例-QQ空间Demo示例程序源代码

    01-导航实例-QQ空间.zip62.4 KB // MJLoginViewController.h Map // //  MJLoginViewController.h //  01-导航实例-QQ ...

  8. iOS多线程的详情使用示例--简进祥

    大家都知道,在开发过程中应该尽可能减少用户等待时间,让程序尽可能快的完成运算.可是无论是哪种语言开发的程序最终往往转换成汇编语言进而解释成机器码来执行.但是机器码是按顺序执行的,一个复杂的多步操作只能 ...

  9. CodeIgniter框架开发的统计程序源代码开放

    文章来源: PHP开发学习门户 自己初学php时,用CodeIgniter框架开发的后台统计程序源代码 程序部分页面如图: 具体配置及下载源代码:http://bbs.phpthinking.com/ ...

随机推荐

  1. 什么是POJO模式

    1.     什么是POJO POJO的名称有多种,pure old java object .plain ordinary java object 等. 按照Martin Fowler的解释是“Pl ...

  2. tomcat8配置管理员后仍然报403

    tomcat8配置管理员后仍然报403   修改conf/tomcat-users.xml <role rolename="manager"/> <role ro ...

  3. return 返回字符串

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  4. 如何用grep命令同时显示匹配行上下的n行 (美团面试题目)

    标准unix/linux下的grep通过以下参数控制上下文 grep -C 5 foo file 显示file文件中匹配foo字串那行以及上下5行grep -B 5 foo file 显示foo及前5 ...

  5. MATLAB中mat2gray的用法【转】

    函数简介 函数功能:实现图像矩阵的归一化操作.所谓"归一化"就是使矩阵的每个元素的值都在0和1之间.该函数在数字图像处理中经常用到. 调用格式: I = mat2gray(A, [ ...

  6. BZOJ 1875 HH去散步(矩阵快速幂)

    题意: 给定一张无向图,每条路的长度都是1,没有自环,可能有重边,给定起点与终点,求从起点走t步到达终点的方案数. 每一步走的时候要求不能走上一条刚刚走的路. 解析: 显然需要搞出个矩阵之后矩乘. 然 ...

  7. HTML5 Web SQL 数据库总结

    Web SQL 数据库 API 并不是 HTML5 规范的一部分,但是它是一个独立的规范,引入了一组使用 SQL 操作客户端数据库的 APIs. 如果你是一个 Web 后端程序员,应该很容易理解 SQ ...

  8. HTML5可用的css reset

    html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, ci ...

  9. python中深copy,浅copy

    版权声明:本文为博主原创文章,未经博主允许不得转载. >>> mylist1 = [1, 2, 3, 4] >>> myl = mylist1 >>&g ...

  10. Qt基本控件及三大布局

    Qt基本控件及三大布局 来源: http://blog.csdn.net/a2604539133/article/details/73920696 Qt基本模块 一.Qt的三大布局 QHBoxLayo ...