cactoos
cactoos copied to clipboard
Async doesn't shutdown ExecutorService
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.
@llorllale/z please, pay attention to this issue
@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!
@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.
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.
@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 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?