对java.lang.Thread类的理解
Thread
类作为对象,其本身具有的功能是顺序执行指定功能(run()
方法,即普通的函数功能)和异步执行指定功能(start()
方法,在不阻塞后续代码执行的同时,执行自身的run()
方法,即多线程特性,开启新线程来执行该方法)。对应的接口为Runnable
。构造函数有如下形式:
Thread()
Allocates a new Thread object.
Thread(Runnable target)
Allocates a new Thread object.
Thread(String name)
Allocates a new Thread object.
Thread(ThreadGroup group, Runnable target)
Allocates a new Thread object.
Thread(ThreadGroup group, String name)
Allocates a new Thread object.
Thread(Runnable target, String name)
Allocates a new Thread object.
Thread(ThreadGroup group, Runnable target, String name)
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group.
Thread(ThreadGroup group, Runnable target, String name, long stackSize)
Allocates a new Thread object so that it has target as its run object, has the specified name as its name, and belongs to the thread group referred to by group, and has the specified stack size.