标签:
多进程:
在操作系统中能(同时)运行多个任务(程序)
多线程:
在同一应用程序中有多个顺序流(同时)执行
创建线程的方法
方式一:
定义一个线程类,它继承类Thread并重写其中的方法run(),方法run()称为线程体。
由于java只支持单继承,用这种方法定义的类不能再继承其他类。
class FirstThread extends Thread
{
public void run()
{
for(int i=0;i<100;i++)
{
System.out.println("FirstThread-->"+i);
}
}
}
class Test
{
public static void main(String args[])
{
//生成线程类的对象
FirstThread ft=new FirstThread();
//启动线程
ft.start();
//ft.run();//千万不能这样写,这是同一个线程内的方法,不是新线程
}
}
标签:
原文地址:http://www.cnblogs.com/ansen312/p/5840194.html