- class Hello implements Runnable
- {
- @Override
- public void run()
- {
- System.out.println(Thread.currentThread().getName()+" say: hi,Java!");
- }
- }
- class ThreadNameTest
- {
- public static void main(String[] args)
- {
- new Thread(new Hello(),"Panda").start();
- new Thread(new Hello()).start();
- }
- }
复制代码 测试结果:- Panda say: hi,Java!
- Thread-0 say: hi,Java!
复制代码 |