线程第四课,线程创建之二,接口

来源:互联网 发布:数据统计岗位职责 编辑:程序博客网 时间:2024/04/28 18:39
package com.pkushutong.DemoThread;/** * 使用Runnable创建线程 * 1、类实现Runnable接口+ 重写run()方法 * 2、启动多线程,使用静态代理 *    1)创建真实角色 *    2)创建代理角色+真实角色引用 *    3)调用.start()启动线程 *     * 推荐使用Runnable创建线程 * 1、避免单继承的局限性 * 2、便于共享资源 * @author dell * */public class Test04 implements Runnable{@Overridepublic void run() {for(int i=0; i<1000; i++){System.out.println("一边写代码");}}}


package com.pkushutong.DemoThread;public class Test02 {public static void main(String[] args) { //1)创建真实角色Test04 t = new Test04(); //2)创建代理角色+真实角色引用Thread thread = new Thread(t); //3)调用.start()启动线程thread.start();for(int i=0; i<1000; i++){System.out.println("一边聊QQ");}}}


0 0