public class OperateThread
{
public static void main(String[] args)
{
Thread thread1=new ExtendsThread();
thread1.start();
Thread thread2=new Thread(new RunnableThread());
thread2.start();
}
}
/*通过继承Thread类,来创建自己的线程*/
class ExtendsThread extends Thread
{
/**
*
* {必须重写父类中的run方法}
*
* @author:developer
*/
public void run()
{
try
{
while(true)
{
System.out.println(getName()+"正在运行。");
Thread.sleep(1000l);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
/*通过实现Runnable接口,来创建自己的线程 */
class RunnableThread implements Runnable
{
/**
*
* {必须实现父类中的run方法}
*
* @author:developer
*/
public void run()
{
try
{
while(true)
{
System.out.println(Thread.currentThread().getName()+"正在运行。");
Thread.sleep(1000l);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}