p { margin-bottom: 0.21cm; }
用继承Thread 类实现线程 即调用线程时 调用参数为空的构造方法 start ();方法多少次都只启动了一个线程 如
TestThead tethead = new TestThead();
// testThead.setDaemon(true);
tethead.start();
tethead.start();
tethead.start();
用实现 Runable 接口的方式调用线程 调用一次 start() 就启动一次线程
TestThead tethead = new TestThead();
new Thread(tethead).start();
new Thread(tethead).start();
new Thread(tethead).start();
new Thread(tethead).start();
本文对比了通过继承Thread类和实现Runnable接口两种方式创建线程的区别。前者多次调用start()仅启动一次线程,后者每次调用start()都会新启动一个线程。
7241

被折叠的 条评论
为什么被折叠?



