创建线程的第一种方式:继承Thread…
2013-12-02 19:24
357 查看
步骤:
1、定义类继承Thread
2、复写Thread类中的run方法
3、调用线程的start方法
作用:启动线程,调用run方法
class Demo extends Thread
{
public void run()
{
for(int x = 0; x<60;
x++)
System.out.println("demo
run!!!!!!!"+x);
}
}
class ThreadDemo
{
public static void main(String[] args)
{
//System.out.println("Hello
World!");
Demo d = new Demo();
d.start();
for(int x = 0; x<60;
x++)
System.out.println("hello
world!!!!!!!"+x);
}
}
1、定义类继承Thread
2、复写Thread类中的run方法
3、调用线程的start方法
作用:启动线程,调用run方法
class Demo extends Thread
{
public void run()
{
for(int x = 0; x<60;
x++)
System.out.println("demo
run!!!!!!!"+x);
}
}
class ThreadDemo
{
public static void main(String[] args)
{
//System.out.println("Hello
World!");
Demo d = new Demo();
d.start();
for(int x = 0; x<60;
x++)
System.out.println("hello
world!!!!!!!"+x);
}
}
相关文章推荐
- 线程的第一种创建方式继承Thread
- 05-多线程(多线程创建的方式一-继承Thread类)1 2 06-多线程(Thread类中的方法&线程名称) 08-多线程(线程的状态)图解
- 创建线程的两种方式:继承Thread类和实现Runnable接口
- 线程 创建和启动线程的两种方式 实现Runnable接口 继承Thread类 重写唯一方法run()
- 线程的创建方式一-----继承Thread类
- 创建线程的第一种方法:继承Thread类
- java 创建线程方式一继承Thread类
- 02_线程的创建和启动_继承Thread方式
- multithreading--创建Thread线程的第一种方式
- 通过继承Thread类的方式创建两个线程
- Java【多线程知识总结(5)】比较继承Thread类创建线程和实现Runnable接口创建线程这两种方式
- Java【多线程知识总结(5)】比较继承Thread类创建线程和实现Runnable接口创建线程这两种方式
- 多线程(二)---创建线程方式一,继承Thread类
- 线程:创建线程有两种方式,一种是继承Thread类,另一种是实现Runnable接口。代码如下:
- Java核心内库-线程-通过继承Thread类创建并启动线程
- boost::thread线程创建方式总结
- Java线程总结(一):创建线程的两种方式Thread和Runnable
- 7种创建线程方式,你知道几种?线程系列Thread(一)
- 创建线程的方法一:继承Thread类
- 基础篇_线程 第 1 集 创建线程方法之继承Thread类