android之java.lang.thread学习

来源:互联网 发布:linux怎么无法退出vim 编辑:程序博客网 时间:2024/06/05 04:38

public classThread extends Objectimplements Runnable 

There are two ways to execute code in a new thread. You can either subclass Thread and overriding its run() method, or construct a new Thread and pass a Runnable to the constructor. In either case, the start() method must be called to actually execute the new Thread.

以上是官网对Thread类的使用方法的介绍。即通过继承Thread类并实现run方法,或将Runnable(或实现Runnable接口的类,即实现run方法)实例传递给Thread类的构造器。然后通过调用start()方法开启线程。

我们先来了解下Thread的状态。在java.lang.Thread.State枚举类型中,有BLOCKED(等待被锁)、NEW(已生成实例,但还未未执行)、RUNNABLE(可能在运行) 、TERMINATED(被终止) 、TIMED_WAITING(等待指定的时间) 、WAITING(等待) 等六种状态。

0 0
原创粉丝点击