logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Lock pattern
Date Thu, 23 Jun 2016 23:45:34 GMT
Good idea! 
Maybe propose this for Java 9?
Looks very reasonable to me. 

Sent from my iPhone

> On 2016/06/24, at 8:32, Gary Gregory <garydgregory@gmail.com> wrote:
> 
> I wonder if anyone knows why Lock is not AutoCloseable.
> 
> This:
> 
>     public static boolean hasManager(final String name) {
>         LOCK.lock();
>         try {
>             return MAP.containsKey(name);
>         } finally {
>             LOCK.unlock();
>         }
>     }
> 
> 
> Seems lame in comparison to:
> 
>     public static boolean hasManager(final String name) {
>         try (LOCK.lock()) {
>             return MAP.containsKey(name);
>         }
>     }
> 
> Which, due to syntax really would be:
> 
>     public static boolean hasManager(final String name) {
>         try (Object o = LOCK.lock()) {
>             return MAP.containsKey(name);
>         }
>     }
> 
> Just wonderin'...
> 
> Gary
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

Mime
View raw message