Java中创建匿名线程主要集中就三中方式:Thread,Runnable,Handler去实现,下面分别介绍之~

一、通过Thread来创建

new Thread()
{
    public void run() {
        System.out.println("wytings1");
    }
}.start();


二、通过继承Runnable来创建

new Thread() {
      public void run() {
          System.out.println("wytings2");
          }
}.start();

三、通过Handler创建(Android)

new Handler().post(new Runnable() {
            @Override
            public void run() {
                System.out.println("wytings3");
            }
        });

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-02-09
  • 2022-02-12
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2022-01-15
  • 2021-04-16
相关资源
相似解决方案