JAVA_Thread_Runable

2804 ワード

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);
}
}
*/
}