vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

Provide vert.x executor adapter which implements ScheduledExecutorService

Open codekrolik2 opened this issue 1 year ago • 7 comments

Describe the feature

Vert.x executor has a number of very useful features, notably the ability to detect and address locked threads. Providing a standard interface for this executor will immensely enhance its utility.

Use cases

e.g. that will add compatibility with Guava ListenableFutures, and all other libraries that use standard java executor.

Contribution

For now I'll just leave this proposal here.

codekrolik2 avatar Dec 16 '23 22:12 codekrolik2

it is not clear exactly what you want to do, can you describe further more and provide example use cases ?

On Sat, Dec 16, 2023 at 11:45 PM codekrolik2 @.***> wrote:

Describe the feature

Vert.x executor has a number of very useful features, notably the ability to detect and address locked threads. Providing a standard interface for this executor will immensely enhance its utility. Use cases

e.g. that will add compatibility with Guava ListenableFutures, and all other libraries that use standard java executor. Contribution

For now I'll just leave this proposal here.

— Reply to this email directly, view it on GitHub https://github.com/eclipse-vertx/vert.x/issues/5036, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXDCSRE3S24FBSIGBDA6LYJYP7PAVCNFSM6AAAAABAX4GI3KVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DIOJYGM2TIMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

vietj avatar Dec 17 '23 08:12 vietj

Something like this:

    int threadCount = 5;
    //ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(threadCount);
    ScheduledExecutorService scheduledExecutor = Vertx.vertx();
    ListeningScheduledExecutorService exec = MoreExecutors.listeningDecorator(scheduledExecutor);
    ListenableFuture<Void> unused = Futures.transform(Futures.immediateFuture("Hello world."),
        s -> {
          System.out.println(s);
          return null;
        },
        exec);

codekrolik2 avatar Dec 17 '23 09:12 codekrolik2

you would like the Vertx interface to extend ScheduledExecutorService ?

vietj avatar Dec 17 '23 11:12 vietj

what are the use cases ?

vietj avatar Dec 17 '23 11:12 vietj

you would like the Vertx interface to extend ScheduledExecutorService ?

Either that, or have a way to adapt is to ScheduledExecutorService.

what are the use cases ?

If I'm using standard ScheduledExecutorService, a thread can be blocked, and that's not detected or reported. Vert.x detects that and prevents blocking. That's a great property that I'd love to leverage in a lightweight workflow engine project I'm currently working on. The idea is that the engine should be lightweight, portable and work everywhere, including limited hardware, like android and embedded platforms. In such environments it's extremely important to minimize the number of used threads, ideally to 1, and if by some programmer's mistake a flow would block a thread - it could severely impact the performance or even completely halt all execution; especially if there is only 1 thread in the pool.

Vert.x provides a great utility in the form of auto-detecting such situations and throwing exceptions / unblocking threads, which also helps to make such hard to detect problems very visible.

codekrolik2 avatar Dec 17 '23 12:12 codekrolik2

what kind of workload do you want to execute with this executor ?

vietj avatar Dec 17 '23 15:12 vietj

It's a universal programmable workflow engine, it can be used for any type of workloads. More details here: https://github.com/ja-css/flower

codekrolik2 avatar Dec 17 '23 21:12 codekrolik2