[concurrency-interest] ScheduledThreadPoolExecutor thread timeout
davidcholmes at aapt.net.au
Sat Feb 1 02:06:18 EST 2014
Zhong Yu writes:
> In this simple example, the JVM never exits:
> public static void main(String args)
> ScheduledThreadPoolExecutor exec =
> new ScheduledThreadPoolExecutor(1);
> exec.schedule( ()-> System.out.println("done"),
> 1, TimeUnit.SECONDS );
> because the core thread cannot timeout.
> This creates a problem in a hot-reload environment, where each new app
> instance creates a new scheduler thread that never terminates. Is
> there a workaround to the effect that the thread can timeout? Thanks.
There's no way to have the thread timeout and still have a functioning
executor when there is a task waiting to be scheduled. If you don't care
about it functioning correctly then call allowCoreThreadTimeOut(true) and
set your desired timeout.
> Zhong Yu
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
More information about the Concurrency-interest