//
// YYViewController.m
// -NSThread-线程的状态
//
// Created by apple on --.
// Copyright (c) 年 itcase. All rights reserved.
//
#import "YYViewController.h"
@interface YYViewController ()
@property(nonatomic,strong)NSThread *thread;
@end
@implementation YYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//创建线程
self.thread=[[NSThread alloc]initWithTarget:self selector:@selector(test) object:nil];
//设置线程的名称
[self.thread setName:@"线程A"];
}
//当手指按下的时候,开启线程
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//开启线程
[self.thread start];
}
-(void)test
{
//获取线程
NSThread *current=[NSThread currentThread];
NSLog(@"test---打印线程---%@",self.thread.name);
NSLog(@"test---线程开始---%@",current.name);
//设置线程阻塞,阻塞秒
NSLog(@"接下来,线程阻塞秒");
[NSThread sleepForTimeInterval:.];
//第二种设置线程阻塞,以当前时间为基准阻塞秒
NSLog(@"接下来,线程阻塞秒");
NSDate *date=[NSDate dateWithTimeIntervalSinceNow:.];
[NSThread sleepUntilDate:date];
for (int i=; i<; i++) {
NSLog(@"线程--%d--%@",i,current.name);
}
NSLog(@"test---线程结束---%@",current.name);
}
@end
//
// YYViewController.m
// -NSThread-线程的状态
//
// Created by apple on --.
// Copyright (c) 年 itcase. All rights reserved.
//
#import "YYViewController.h"
@interface YYViewController ()
@property(nonatomic,strong)NSThread *thread;
@end
@implementation YYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//创建线程
self.thread=[[NSThread alloc]initWithTarget:self selector:@selector(test) object:nil];
//设置线程的名称
[self.thread setName:@"线程A"];
}
//当手指按下的时候,开启线程
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//开启线程
[self.thread start];
}
-(void)test
{
//获取线程
NSThread *current=[NSThread currentThread];
NSLog(@"test---打印线程---%@",self.thread.name);
NSLog(@"test---线程开始---%@",current.name);
//设置线程阻塞,阻塞秒
NSLog(@"接下来,线程阻塞秒");
[NSThread sleepForTimeInterval:.];
//第二种设置线程阻塞,以当前时间为基准阻塞秒
NSLog(@"接下来,线程阻塞秒");
NSDate *date=[NSDate dateWithTimeIntervalSinceNow:.];
[NSThread sleepUntilDate:date];
for (int i=; i<; i++) {
NSLog(@"线程--%d--%@",i,current.name);
if (==i) {
//结束线程
[NSThread exit];
}
}
NSLog(@"test---线程结束---%@",current.name);
}
@end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有