FloodLimit's executor hangs

All your suggestions, requests and ideas for future development
Post Reply
kgyrtkirk
Posts: 2
Joined: 19 Apr 2016, 21:06

FloodLimit's executor hangs

Post by kgyrtkirk »

hi,

i'm using filebot to create a custom tool for myself - and i noticed something wierd...
in the current dev version:
* the TMDbClient has 2 static FloodLimit objects
* the FloodLimit object has a private ScheduledThreadPoolExecutor, and it only schedules tasks to it...the executor itself never get shutdown-ed...

on my system, this leads to an exit hang...simplified example which hangs:

public class FloodLimitTest {
public static void main(String[]a) throws Exception {
final FloodLimit fl = new FloodLimit(1, 3, TimeUnit.SECONDS);
fl.acquirePermit();
System.out.println("exiting main");
}
}

i'm not sure how this doesn't happend before...the code looks at least 2 years old - or my machines are picky? ;)

cheers
kgyrtkirk
Posts: 2
Joined: 19 Apr 2016, 21:06

Re: FloodLimit's executor hangs

Post by kgyrtkirk »

quick fix (for me at least ;)

diff --git a/source/net/filebot/web/FloodLimit.java b/source/net/filebot/web/FloodLimit.java
index e050125..0d6d1c1 100644
--- a/source/net/filebot/web/FloodLimit.java
+++ b/source/net/filebot/web/FloodLimit.java
@@ -17,6 +17,8 @@ public class FloodLimit {
this.permits = new Semaphore(permitLimit, true);
this.releaseDelay = releaseDelay;
this.timeUnit = timeUnit;
+ timer.setKeepAliveTime(1,TimeUnit.SECONDS);
+ timer.allowCoreThreadTimeOut(true);
}

public ScheduledFuture<?> acquirePermit() throws InterruptedException {
User avatar
rednoah
The Source
Posts: 23932
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: FloodLimit's executor hangs

Post by rednoah »

You could also try to make them Daemon threads. I guess it's non-Daemon threads by default. For FileBot it doesn't make a difference because it'll use System.exit() to shutdown.

EDIT:

See last commit. My solution is different from yours though.
:idea: Please read the FAQ and How to Request Help.
Post Reply