码迷,mamicode.com
首页 > 编程语言 > 详细

java 多线程-Runnable接口

时间:2019-08-05 21:48:41      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:ati   接口   start   stat   ble   对象   new   线程   oid   

  • 单继承具有局限性,推荐使用Runnable接口,启动线程必须借用Thread类对象
  • new Thread(Run).start()

    public void run()
    {
    for(int i=0;i<5;i++)
    {
        System.out.println("aa");
    }
    }
    
    public static void main(String[]args)
    {
    ThreadDownload ra=new ThreadDownload();
    Thread it=new Thread(ra);
    it.start();
    
    //或者
    new Thread(new ThreadDownload()).start();
    
    for(int i=0;i<5;i++)
    {
        System.out.println("ff");
    }
    }
  • java 多线程-Runnable接口

    标签:ati   接口   start   stat   ble   对象   new   线程   oid   

    原文地址:https://blog.51cto.com/14437184/2426858

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!