您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java中有什么特殊monitor

2024/4/24 16:06:36发布20次查看
说明
1、this monitor:在成员方法上的synchronized,就是this monitor,等价于在方法中使用synchronized(this)
2、class monitor:在静态方法上的synchronized,就是class monitor,等价于在静态方法中使用synchronized(xxx.class)
实例
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();    }}
以上就是java中有什么特殊monitor的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product