package com.ninemax.application.multithread;/** * 多线程 * * @author Darker * */public class RunnableTest implements Runnable { private String name; public RunnableTest(String name){ this.name=name; } @Override public void run() { for(int i=0;i<5;i++){ System.out.println(name+"运行:"+i); try { Thread.sleep((int)Math.random()*10); } catch (InterruptedException e) { e.printStackTrace(); } } } public static void main(String[] args) { new Thread(new RunnableTest("A")).start(); new Thread(new RunnableTest("B")).start(); }}
运行结果:
A运行:0B运行:0B运行:1B运行:2B运行:3B运行:4A运行:1A运行:2A运行:3A运行:4
remark:
结果很有特点..