Skip to content

Instantly share code, notes, and snippets.

@vietj
Created July 22, 2025 08:36
Show Gist options
  • Save vietj/136078b436e5310b1a04da0e491ebe7c to your computer and use it in GitHub Desktop.
Save vietj/136078b436e5310b1a04da0e491ebe7c to your computer and use it in GitHub Desktop.
package io.vertx.core;
import io.netty.channel.EventLoop;
import io.vertx.core.internal.ContextInternal;
import io.vertx.core.internal.VertxInternal;
public class Main {
public static void main(String[] args) {
// From netty/vertx event loop thread
// Netty
// Vertx
// Observability
// Application
// Vertx -> Application
// Dispatch on the correct thread : event-loop / worker / virtual thread
Runnable application = () -> {
// Application code
System.out.println(Thread.currentThread() + " - " + Vertx.currentContext());
};
VertxInternal vertx = (VertxInternal) Vertx.vertx();
ContextInternal context = vertx.createWorkerContext();
EventLoop eventLoop = context.nettyEventLoop();
eventLoop.execute(() -> {
// Emit == execute + dispatch
// runContextContext == execute + dispatch but always schedule a task
// Like an IO call
// We enter vertx
// Vertx running on event-loop -- message passing -> Vertx running on worker thread - Application on worker
// Vertx running on worker thread -- message passing -> Vertx running on event loop
// Observability here
// tracing
// Application dispatch
context.dispatch(application);
// Message passing
context.execute(() -> {
// We are on application thread but no context association yet
application.run();
// Application dispatch
context.dispatch(application);
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment