标签:
Thread 和 Runnable
public class teach1 { public static void main(String[] args) { Model model = new Model(); new Thread(model).start(); new Thread(model).start(); } } class Model implements Runnable{ int num = 20; @Override public void run() { // TODO Auto-generated method stub while(num>0){ System.out.println(Thread.currentThread().getName()+" "+num); num--; } } }
class Model extends Thread{ int num = 20; @Override public void run() { // TODO Auto-generated method stub while(num>0){ System.out.println(Thread.currentThread().getName()+" "+num); num--; } } }
我怎么想也不能再另一个类里对该类的成员变量num进行开多个线程操作
带你玩转java多线程系列 二 Thread 和 Runnable
标签:
原文地址:http://www.cnblogs.com/winAlaugh/p/5474734.html