??????
????????ó?????????????????ReentrantLock????????????????????Щ??
????????1?????????ò???????????????????У???????У?
????a???????????????????????????????????′μ?????????????????????????????????У??????????????
????b????????潻????????н????????????????????ε?????o???????У????????????????
???????????????????????з???????????????У????磺???????????????????Щ????????????????????????
1 private ReentrantLock lock = new ReentrantLock();
2
3                 if (lock.tryLock()) {  //????????lock????????????false???????????????????Ч??
4
5                     try {
6
7                        //????
8
9                     } finally {
10                         lock.unlock();
11                     }
12
13                 }
????e.g ??????????????????????????δ?????????????????ж??ε????????
????????2?????????ò??????????У??????????У??????У?????synchronized??
????????????????????????????????????ó?????????????????????????????????????
????????synchronized?????????????????????????jvm??????????????С??????Lock?и??????????????????????????????synchronized??????????
???????????????????????????????磺????????????????????????????????
????ReentrantLock????????????????
????private ReentrantLock lock = new ReentrantLock(); //???????false?????????
????private ReentrantLock lock = new ReentrantLock(true); //?????
????try {
????lock.lock(); //??????????????????????????????????????Ч??
????//????
????} finally {
????lock.unlock();
????}
??????????????????????
???????????£????????????????????У?????????????????????????????????
?????????????£????????????????jvm???????????δ?????????????????????????????????????????
????????3?????????ò??????????У???????????????????????У?????????У?
??????????????????2??????????????????????????????????????????????С?
????????????????????????????????????????????????????????????????????????????
1   try {
2                     if (lock.tryLock(5?? TimeUnit.SECONDS)) {  //????????lock????????5s???????????????????5s?????????????????false???????
3
4
5                         try {
6
7
8                             //????
9
10
11                         } finally {
12                             lock.unlock();
13                         }
14
15
16                     }
17                 } catch (InterruptedException e) {
18                     e.printStackTrace(); //????????ж??(interrupt)??????InterruptedException
19                 }
20
????????4?????????ò??????????У??????С???????ж???????е??????????????????????????
????synchronized??Lock???????????????????ж?(interrupt)????????????????lockInterruptibly()??????ж????????????????????2?????????????г??????????ж?????????
??????????????????????Щ?????????????á??磺???????????????е???????????????????????????????????????
????try {
????lock.lockInterruptibly();
????//????
????} catch (InterruptedException e) {
????e.printStackTrace();
????} finally {
????lock.unlock();
????}
?????????????
???????????????????????“?????????????(Parallel computing)”??????????????reentrant??re-entrant?????????????????????????????????ν???????????????????? ???????н???????????????????????????????????????????????????????
??????????????????ó?????????????ReentrantLock?о????????????????
????1??lock  ??????????????????????????????
????2??lockInterruptibly ???????????????????ж????????????У???????ж??
????3??tryLock() ????????????????????true.??????????????????
????4??tryLock(long time??TimeUnit unit) ???????????????????
????5??unlock()??????????