讲解得太细致啦

  • 时间:
  • 浏览:0
  • 来源:决战梭哈棋牌APP下载_决战梭哈棋牌APP官网

我是服了!

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



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

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();
	}

}

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(30L);
			ThreadB b = new ThreadB(service);
			b.start();
			System.out.println("have set stop order.");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}



但真的一路演练一下,