zoukankan      html  css  js  c++  java
  • when to use reentrant lock

    The answer is pretty simple -- use it when you actually need something it provides that synchronized doesn't,

    like timed lock waits, interruptible lock waits, non-block-structured locks, multiple condition variables, or lock polling.

    ReentrantLock also has scalability benefits, and you should use it if you actually have a situation that exhibits high contention,

    but remember that the vast majority of synchronized blocks hardly ever exhibit any contention, let alone high contention.

    I would advise developing with synchronization until synchronization has proven to be inadequate,

    rather than simply assuming "the performance will be better" if you use ReentrantLock. Remember, these are advanced tools for advanced users.

    (And truly advanced users tend to prefer the simplest tools they can find until they're convinced the simple tools are inadequate.)

    As always, make it right first, and then worry about whether or not you have to make it faster.

  • 相关阅读:
    dirs命令
    pwd命令
    ls命令
    rmdir命令
    install命令和cp命令的区别
    ./configure,make,make install的作用
    install 命令
    Make 命令
    linux configure使用方法
    Linux下which、whereis、locate、find命令的区别
  • 原文地址:https://www.cnblogs.com/glf2046/p/4885399.html
Copyright © 2011-2022 走看看