package com.kk.thread; /* * 继承Thread和实现Runnable接口都可以实现多线程 * 继承Thread可以修改线程的一些属性,例如name、daemon等 * 一般采用实现Runnable接口 */ public class RunableTest { public static void main(String[] args) { RunnableClassTest r = new RunnableClassTest(); // new Thread(r).start(); // new Thread(r).start(); // new Thread(r).start(); // new Thread(r).start(); r.getThread().start(); r.getThread().start(); r.getThread().start(); r.getThread().start(); while (true) System.out.println(Thread.currentThread().getName()); } } class RunnableClassTest /*implements Runnable */{ int i=0; private class InnerThread extends Thread{ public void run() { while(true){ System.out.println(Thread.currentThread().getName()); System.out.println(++i); } } } public Thread getThread(){ return new InnerThread(); } /* public void run() { while (true){ System.out.println(Thread.currentThread().getName()); System.out.println(++i); } } */ }