讲解得太细致啦

  • 时间:
  • 浏览:1

package test;

public class ThreadB extends Thread {
	private Service service;
	public ThreadB(Service service) {
		super();
		this.service = service;
	}
	
	@Override
	public void run() {
		service.stopMethod();
	}

}





package test;

public class ThreadA extends Thread {
	private Service service;
	public ThreadA(Service service) {
		super();
		this.service = service;
	}
	
	@Override
	public void run() {
		service.runMethod();
	}

}

另有2个 synchronized关键字,能讲一百多页,搞出几3个小举例。

但真的一路演练一下,

package test;



public class Run {

	public static void main(String[] args) throws InterruptedException {
		// TODO Auto-generated method stub
		try {
			Service service = new Service();
			ThreadA a = new ThreadA(service);
			a.start();
			Thread.sleep(10000L);
			ThreadB b = new ThreadB(service);
			b.start();
			System.out.println("have set stop order.");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}

我是服了!

对这一关键的应用场景还是了解了统统的。