[concurrency-interest] ScheduledThreadPoolExecutor thread timeout

Oleksiy Stashok oleksiy.stashok at oracle.com
Sat Feb 1 00:10:33 EST 2014


May be I'm missing something in your question, but IMO if you don't want 
a core thread to be created - just pass 0 as a constructor parameter.

     public static void main(String[] args)
     {
         ScheduledThreadPoolExecutor exec =
             new ScheduledThreadPoolExecutor(0);
         exec.schedule( ()-> System.out.println("done"),
             1, TimeUnit.SECONDS );
     }


WBR,
Alexey.

On 31.01.14 20:19, Zhong Yu wrote:
> 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.
>
> Zhong Yu
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest



More information about the Concurrency-interest mailing list