A thread is a thread of execution in a program.
一个线程 是一个 程序中的线程
The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
Java虚拟机 允许 一个应用 有 多个线程, 同时执行
Every thread has a priority.
每个线程有一个优先级
Threads with higher priority are executed in preference to threads with lower priority.
有高优先级的线程, 优于 低优先级的线程被执行
Each thread may or may not also be marked as a daemon.
每个线程 可以 或者不 被标记为一个 守护线程
When code running in some thread creates a new Thread object,
当运行中的代码, 创建了一个 新的线程 对象时,
the new thread has its priority initially set equal to the priority of the creating thread,
这个新线程, 有它自己的 初始化优先级 (和创建它的线程具有一样的 优先级)
and is a daemon thread if and only if the creating thread is a daemon.
When a Java Virtual Machine starts up, there is usually a single non-daemon thread
当 一个Java虚拟机开始运行时, 通常有一个 单独的 非守护线程
(which typically calls the method named main of some designated class).
The Java Virtual Machine continues to execute threads until either of the following occurs:
Java虚拟机, 持续 执行线程, 直到下面的事情发生
The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
类的 exit方法, 被调用, 安全管理器 被 允许 这个离开操作
All threads that are not daemon threads have died,
所有的 非守护线程, 都 死亡
either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
或者通过 调用返回, 或 抛 传播到 run方法之外的 异常
There are two ways to create a new thread of execution.
有2种方式创建 一个新的线程
方式1_继承_重写run
One is to declare a class to be a subclass of Thread.
一种是, 声明一个类, 继承Thread, 成为 Thread的子类
This subclass should override the run method of class Thread.
这个子类, 应该要 重写Thread中的 run方法
An instance of the subclass can then be allocated and started.
子类的实例, 能够被 分配 和 开始
For example, a thread that computes primes larger than a stated value could be written as follows:
例如, 一个线程,
方式2_实现Runnable接口
The other way to create a thread is to declare a class that implements the Runnable interface.
另一种创建线程的方式 是 声明一个类(实现 Runnable接口)
That class then implements the run method.
这个类, 然后去 实现 run方法
An instance of the class can then be allocated, passed as an argument when creating Thread, and started.
一个类的实例 然后就可以 被分配, 传递一个参数, 当 创建线程, 开始后
The same example in this other style looks like the following:
一样的例子, 如下
Every thread has a name for identification purposes.
每一个线程, 有一个 定义定义目的
More than one thread may have the same name.
不止一个线程, 可以有 相同的名字
If a name is not specified when a thread is created, a new name is generated for it.
当创建一个线程的时候, 如果名字没有指明, 一个新的名字会 生成
Unless otherwise noted,
passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.
传递一个 null参数 给到 构造器 或 方法, 会引起一个 空指针异常