Java线程入门
一、继承Thread:
示例:
public class my extends Thread
{
public void run(){};
public static void main(String[] args)
{
my t=new my();
t.start();
}
}
二、实现Runnable接口:
要定义一个Thread,并且重载start方法:
public class my implements Runnable
{
Thread t=null;
public my()
{
t=new Thread(this);
t.start();
}
public void run()
{
System.out.println("Laughing");
}
public static void main(String args[])
{
new my();
}
}
三、
Thread t=new Thread(new Runnable()
{
public void run()
{
//d.setVisible(true);
}
}) ;
t.start(); //启动一个线程运行对话框