java multithreading -Runnable Interface

  • Single inheritance has limitations, recommended Runnable interface, start the thread must borrow Thread class object
  • 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");
    }
    }

Guess you like

Origin blog.51cto.com/14437184/2426858