说明
1、this monitor:在成员方法上的synchronized,就是this monitor,等价于在方法中使用synchronized(this)
2、class monitor:在静态方法上的synchronized,就是class monitor,等价于在静态方法中使用synchronized(XXX.class)
1、什么是店中店?店中店是全诚商多用户版的一大特色,它既是独立的个体,又具有群集功能。我们做个例子说明:假设尊贵的您现实生活中租赁了一个店面,店面空间很大,您可以把您的店面分割成很多独立空间再向别人转租,这样您可以额外获得一部分租赁费用收入,借以减少你的个人租赁费用投入,还能起到活跃销售场所的气氛,俗话说:货卖一堆吗。你租赁的店面可以完全分割成很多空间向外转租,也可以自己保留一块空间为自己销售商品
实例
public class Main {
public synchronized void method1(){
System.out.println(Thread.currentThread().getName()+" method1");
try{
TimeUnit.MINUTES.sleep(5);
}catch (InterruptedException e){
e.printStackTrace();
}
}
public synchronized void method2(){
System.out.println(Thread.currentThread().getName()+" method2");
try{
TimeUnit.MINUTES.sleep(5);
}catch (InterruptedException e){
e.printStackTrace();
}
}
public static void main(String[] args) throws InterruptedException {
Main m = new Main();
new Thread(m::method1).start();
new Thread(m::method2).start();
}
}










