Thread构造函数详解
线程构造函数详解
逐句解析
- 创建线程对象
原句:Allocates a new Thread object.
译文:创建新的线程对象。
解析:
- Allocates:分配/创建
- Thread:程序执行线程
- object:程序对象
结构:省略主语 + 谓语(Allocates) + 宾语
含义:该构造函数用于实例化线程对象
- 构造函数等效形式
原句:This constructor has the same effect as Thread(null, target, gname), where gname is a newly generated name.
译文:该构造函数等效于Thread(null, target, gname),其中gname为新生成的名称。
解析:
- constructor:构造函数
- has the same effect as:等效于
- null:空值
- target:执行目标
- gname:生成的名称
结构:主句 + where引导的定语从句
含义:此简化构造函数与完整构造函数功能相同
- 自动命名规则
原句:Automatically generated names are of the form “Thread-”+n, where n is an integer.
译文:自动生成名称格式为"Thread-"+n,其中n为整数。
解析:
- Automatically:自动
- are of the form:格式为
- integer:整数
结构:主系表结构 + where从句
含义:线程名称格式示例:Thread-0、Thread-1等
- target参数说明
原句:target - the object whose run method is invoked when this thread is started.
译文:target - 线程启动时执行其run方法的对象。
解析:
- target:执行目标
- run method:线程执行体
- invoked:调用
结构:参数定义 + 定语从句
含义:指定线程要执行的任务对象
- null参数处理
原句:If null, this classes run method does nothing.
译文:若为null,则线程run方法不执行任何操作。
解析:
- does nothing:空操作
结构:条件状语从句 + 主句
含义:未指定任务时线程立即终止
功能总结
该构造函数用于:
- 实例化线程对象
- 自动生成线程名称(格式:Thread-序号)
- 通过target参数指定执行任务
- target为null时线程不执行任务直接终止Thread构造函数详解
逐句翻译和解释
原句1:
Allocates a new Thread object.
中文翻译
分配一个新的线程对象。
词汇解释
Allocates (动词) - 分配、创建空间
Thread (名词) - 线程(计算机程序的执行路径)
object (名词) - 对象(程序中的东西)
句子结构
主语(省略了) + 谓语(Allocates) + 宾语(a new Thread object)
简单理解
(这个构造函数)创建了一个新的线程对象
原句2:
This constructor has the same effect as Thread (null, target, gname), where gname is a newly generated name.
中文翻译
这个构造函数的效果和Thread(null, target, gname)一样,其中gname是一个新生成的名字。
词汇解释
constructor (名词) - 构造函数(创建对象时调用的特殊方法)
has the same effect as (词组) - 和…效果一样
null (名词) - 空值(什么都没有)
target (名词) - 目标(要执行的任务)
gname (变量名) - 生成的名字
generated (动词) - 生成、创建
句子结构
主语(This constructor) + 谓语(has) + 宾语(the same effect as…) + 从句(where…)
简单理解
这个简单的构造函数其实和一个复杂的构造函数功能一样
原句3:
Automatically generated names are of the form “Thread-”+n, where n is an integer.
中文翻译
自动生成的名字格式是"Thread-“+n,其中n是一个整数。
词汇解释
Automatically (副词) - 自动地
generated (动词) - 生成
names (名词) - 名字
are of the form (词组) - 格式是…
Thread- (字符串) - 线程-
n (变量) - 数字
integer (名词) - 整数(1,2,3这样的数字,不是1.5这样的小数)
句子结构
主语(Automatically generated names) + 谓语(are) + 表语(of the form…) + 从句(where…)
简单理解
线程会自动起名字,格式是"Thread-0”、"Thread-1"这样
原句4:
target – the object whose run method is invoked when this thread is started.
中文翻译
target - 当这个线程启动时,其run方法会被调用的那个对象。
词汇解释
target (名词) - 目标
object (名词) - 对象
whose (关系代词) - 谁的
run method (名词) - run方法(线程要执行的具体代码)
invoked (动词) - 调用、执行
when (连词) - 当…时候
thread (名词) - 线程
started (动词) - 启动
句子结构
这是一个参数说明,解释target参数的作用
简单理解
target就是要执行的任务对象
原句5:
If null, this classes run method does nothing.
中文翻译
如果是null,这个类的run方法什么都不做。
词汇解释
If (连词) - 如果
null (名词) - 空值
classes (名词) - 类的(这里指Thread类)
does nothing (词组) - 什么都不做
句子结构
条件句:If null, + 主语(this classes run method) + 谓语(does) + 宾语(nothing)
简单理解
如果没有任务,线程启动后就直接结束
总结
这个构造函数用来创建一个线程对象:
会自动给线程起名字(Thread-0, Thread-1…)
可以指定要执行的任务(target)
如果不指定任务,线程启动后就直接结束了