深入理解Java内存模型(五)——锁

深入理解Java内存模型(五)——锁

FROM:http://www.infoq.com/cn/articles/ java-memory-model-5

锁的释放-获取建立的happens before 关系

锁是 java并发编程中最重要的同步机制。锁除了让临界区互斥执行外,还可以让释放锁的线程向获取同一个锁的线程发送消息。

下面是锁释放-获取的示例代码:

class MonitorExample {
    int a = 0;

    public synchronized void writer() {  //1
        a++;                             //2
    }                                    //3

    public synchronized void reader() {  //4
        int i = a;                       //5
        ……
    }                                    //6
}
好烂啊有点差凑合看看还不错很精彩 (No Ratings Yet)
Loading...
403 views

3 thoughts on “深入理解Java内存模型(五)——锁

  1. It’s a shame you don’t have a donate button! I’d most certainly donate to this brilliant blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this website with my Facebook group. Chat soon!

  2. Greetings I am so grateful I found your weblog, I really found you by error, while I was looking on Google for something else, Anyhow I am here now and would just like to say thanks a lot for a marvelous post and a all round exciting blog (I also love the theme/design), I don’t have time to read through it all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read much more, Please do keep up the fantastic job.

  3. Great tremendous issues here. I am very glad to peer your article. Thanks so much and i’m looking forward to touch you. Will you kindly drop me a e-mail?

发表评论

电子邮件地址不会被公开。 必填项已用*标注

跳至工具栏