cactoos icon indicating copy to clipboard operation
cactoos copied to clipboard

Async doesn't shutdown ExecutorService

Open fabriciofx opened this issue 6 years ago • 6 comments

Here in Async it creates a new ExecutorService and here it submit the Func to Executor but it doesn't shutdown the ExecutorService. So I think it should call this.executor.shutdown() after submit.

fabriciofx avatar Jul 20 '19 21:07 fabriciofx

@llorllale/z please, pay attention to this issue

0crat avatar Jul 21 '19 01:07 0crat

@fabriciofx/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

0crat avatar Jul 21 '19 01:07 0crat

@fabriciofx I think it should only shutdown the ExecutorService if it has created one by it self. If an ExecutorService has been passed into it it shouldn't shut it down.

svendiedrichsen avatar Aug 23 '19 23:08 svendiedrichsen

In that case only a ThreadFactory is passed into the method. The ExecutorService is created by Async class (Executors.newSingleThreadExecutor(fct)), so it's the class responsibility to close it.

tess1o avatar Sep 25 '19 14:09 tess1o

@svendiedrichsen @tess1o @victornoel please, look the Async class:

   public Async(final Func<X, Y> fnc) {
        this(fnc, Executors.defaultThreadFactory());
    }

If the user pass only a Func to Async it'll create an Executor. So, Async must shutdown if and only if has been created by itself.

fabriciofx avatar Jul 04 '20 14:07 fabriciofx

@fabriciofx good point. But we can't just shut it down after the submit, since we don't know if it's going to execute the task right now or later.

Actually I wonder what's the real need for such a class. I think we should delete it or find another abstraction that really makes sense. If one wants to execute something asynchronously, there already are far better, mature and well thoughts abstractions existing in the java std lib IMHO.

The only interesting thing I could think of right now, is a Scalar<T> that executes the task as soon a it is created but the Future.get() is called in value(). Or in other words, a Scalar that wraps a Future basically.

Any opinion?

victornoel avatar Jul 05 '20 10:07 victornoel