zoukankan      html  css  js  c++  java
  • Groovy死锁例子

    Groovy死锁例子

    import java.util.concurrent.atomic.AtomicInteger

    class DeadLock{

    static AtomicInteger lock = new AtomicInteger()

    static AtomicInteger lock2 = new AtomicInteger()

    static message1(){

    //If no thread obtains the lock, then execute

    synchronized(lock){

    println "I am" + Thread.currentThread().getName() + ", I am printing a message"

    message2()

                  }

           }

    static message2(){

    synchronized(lock2){

    println "I am" + Thread.currentThread().getName() + ", I am printing a message"

    message1()

                  }

           }

    static void main(String... args) {

                  Thread.start{

    message1()

                  }

                  Thread.start{

    message2()

                  }

           }

    }

    1. 运行时用这个参数-Dcom.sun.management.jmxremote

    Image(1)

    2. 用JConsole查看锁情况

    Image(2)

    Thread 1

    Image(3)

    Thread 2

    Image(4)

  • 相关阅读:
    tomcat-1
    oscache-2
    oscache-3
    oscache-1
    oscache-4
    缓存概要
    Criterion & DetachedCriteria
    Hibernate <查询缓存>
    Hibernate <二级缓存>
    Hibernate <一级缓存>
  • 原文地址:https://www.cnblogs.com/cando/p/2287079.html
Copyright © 2011-2022 走看看