1- /**
1+ /*
22 * Copyright (c) 2014-2023, stateful.co
33 * All rights reserved.
44 *
6161 * {@link java.util.concurrent.Executors#callable(Runnable)}. If you
6262 * want to avoid checked exceptions, use {@link #callQuietly()}.
6363 *
64- * @author Yegor Bugayenko (yegor@tpc2.com)
65- * @version $Id$
6664 * @since 0.6
6765 * @param <T> Type of result
6866 * @see <a href="http://www.yegor256.com/2014/05/18/cloud-autoincrement-counters.html">Atomic Counters at Stateful.co</a>
@@ -143,14 +141,11 @@ public Atomic(final Callable<T> clbl, final Lock lck, final String lbl,
143141 @ Override
144142 public T call () throws Exception {
145143 final Thread hook = new Thread (
146- new Runnable () {
147- @ Override
148- public void run () {
149- try {
150- Atomic .this .lock .unlock (Atomic .this .label );
151- } catch (final IOException ex ) {
152- throw new IllegalStateException (ex );
153- }
144+ () -> {
145+ try {
146+ this .lock .unlock (this .label );
147+ } catch (final IOException ex ) {
148+ throw new IllegalStateException (ex );
154149 }
155150 }
156151 );
@@ -162,7 +157,6 @@ public void run() {
162157 if (age > this .max ) {
163158 throw new IllegalStateException (
164159 Logger .format (
165- // @checkstyle LineLength (1 line)
166160 "lock \" %s\" is stale (%d failed attempts in %[ms]s, which is over %[ms]s)" ,
167161 this .lock , attempt , age , this .max
168162 )
@@ -173,13 +167,11 @@ public void run() {
173167 TimeUnit .MINUTES .toMillis (1L ),
174168 Math .abs (
175169 100L + (long ) Atomic .RANDOM .nextInt (100 )
176- // @checkstyle MagicNumber (1 line)
177170 + (long ) StrictMath .pow (5.0d , (double ) attempt + 1.0d )
178171 )
179172 );
180173 Logger .info (
181174 this ,
182- // @checkstyle LineLength (1 line)
183175 "lock \" %s\" is occupied for %[ms]s already, attempt #%d in %[ms]s" ,
184176 this .lock , age , attempt , delay
185177 );
@@ -193,12 +185,13 @@ public void run() {
193185 this .lock .unlock (this .label );
194186 }
195187 Runtime .getRuntime ().removeShutdownHook (hook );
196- Logger .info (
197- this ,
198- // @checkstyle LineLength (1 line)
199- "\" %s\" took %[ms]s after %d attempt(s)" ,
200- this .lock , System .currentTimeMillis () - start , attempt + 1L
201- );
188+ if (Logger .isInfoEnabled (this )) {
189+ Logger .info (
190+ this ,
191+ "\" %s\" took %[ms]s after %d attempt(s)" ,
192+ this .lock , System .currentTimeMillis () - start , attempt + 1L
193+ );
194+ }
202195 }
203196 }
204197
0 commit comments