@@ -135,33 +135,33 @@ private static synchronized boolean deleteIfEmpty(MasterCleaner caller) {
135135
136136 private MasterCleaner () {
137137 Thread cleanerThread = new Thread (() -> {
138- long lastNonEmpty = System .currentTimeMillis ();
139- long now ;
140- long lastMasterRun = 0 ;
141- while ((now = System .currentTimeMillis ()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty (MasterCleaner .this )) {
142- if (!cleaners .isEmpty ()) { lastNonEmpty = now ; }
143- try {
144- Reference <?> ref = impl .referenceQueue .remove (MASTER_CLEANUP_INTERVAL_MS );
145- if (ref instanceof CleanerRef ) {
146- ((CleanerRef ) ref ).clean ();
147- }
148- // "now" is not really *now* at this point, but off by no more than MASTER_CLEANUP_INTERVAL_MS
149- if (lastMasterRun + MASTER_CLEANUP_INTERVAL_MS <= now ) {
150- masterCleanup ();
151- lastMasterRun = now ;
152- }
153- } catch (InterruptedException ex ) {
154- // Can be raised on shutdown. If anyone else messes with
155- // our reference queue, well, there is no way to separate
156- // the two cases.
157- // https://groups.google.com/g/jna-users/c/j0fw96PlOpM/m/vbwNIb2pBQAJ
158- break ;
159- } catch (Exception ex ) {
160- Logger .getLogger (Cleaner .class .getName ()).log (Level .SEVERE , null , ex );
138+ long lastNonEmpty = System .currentTimeMillis ();
139+ long now ;
140+ long lastMasterRun = 0 ;
141+ while ((now = System .currentTimeMillis ()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty (MasterCleaner .this )) {
142+ if (!cleaners .isEmpty ()) { lastNonEmpty = now ; }
143+ try {
144+ Reference <?> ref = impl .referenceQueue .remove (MASTER_CLEANUP_INTERVAL_MS );
145+ if (ref instanceof CleanerRef ) {
146+ ((CleanerRef ) ref ).clean ();
147+ }
148+ // "now" is not really *now* at this point, but off by no more than MASTER_CLEANUP_INTERVAL_MS
149+ if (lastMasterRun + MASTER_CLEANUP_INTERVAL_MS <= now ) {
150+ masterCleanup ();
151+ lastMasterRun = now ;
161152 }
153+ } catch (InterruptedException ex ) {
154+ // Can be raised on shutdown. If anyone else messes with
155+ // our reference queue, well, there is no way to separate
156+ // the two cases.
157+ // https://groups.google.com/g/jna-users/c/j0fw96PlOpM/m/vbwNIb2pBQAJ
158+ break ;
159+ } catch (Exception ex ) {
160+ Logger .getLogger (Cleaner .class .getName ()).log (Level .SEVERE , null , ex );
162161 }
163- LOG .log (Level .FINE , "MasterCleaner thread {0} exiting" , Thread .currentThread ());
164- }, "JNA Cleaner" );
162+ }
163+ LOG .log (Level .FINE , "MasterCleaner thread {0} exiting" , Thread .currentThread ());
164+ }, "JNA Cleaner" );
165165 LOG .log (Level .FINE , "Starting new MasterCleaner thread {0}" , cleanerThread );
166166 cleanerThread .setDaemon (true );
167167 cleanerThread .start ();
0 commit comments