5.6 实现Runable接口定义线程和直接继承Thead类定义线程的区别

来源:互联网 发布:阿里云邮箱账号格式 编辑:程序博客网 时间:2024/05/29 19:34

p { margin-bottom: 0.21cm; }

用继承Thread类实现线程即调用线程时 调用参数为空的构造方法 start();方法多少次都只启动了一个线程 如

TestTheadtethead = newTestThead();

//testThead.setDaemon(true);

tethead.start();

tethead.start();

tethead.start();

用实现Runable接口的方式调用线程 调用一次start()就启动一次线程

TestTheadtethead = newTestThead();

newThread(tethead).start();

newThread(tethead).start();

newThread(tethead).start();

newThread(tethead).start();