Laughing

 

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();        //启动一个线程运行对话框

posted on 2011-12-08 20:25  巨富一生  阅读(132)  评论(0编辑  收藏  举报

导航