Page 1 of 1

FloodLimit's executor hangs

Posted: 19 Apr 2016, 21:43
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

Re: FloodLimit's executor hangs

Posted: 19 Apr 2016, 21:52
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 {

Re: FloodLimit's executor hangs

Posted: 20 Apr 2016, 06:19
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.