实现Runnable接口,通过Thread启动多线程

来源:互联网 发布:讲你知有没有国语 编辑:程序博客网 时间:2024/05/17 06:18
package com.xiner.demo;public class Demo implements Runnable{    boolean flag = false;    public void run(){        for(int i=0;i<10;i++){            System.out.println("-----"+i);        }    }    public void ac(){        Thread th1 = new Thread(Demo.this);        th1.start();    }    public static void main(String[] args){        Demo d1 = new Demo();        Demo d2 = new Demo();        d1.ac();        d2.ac();    }}
阅读全文
0 0
原创粉丝点击