Hugo Costa
01/10/2025, 4:16 PMfun main(args: Array<String>) {
val server = NETTY_SERVER
Runtime.getRuntime().addShutdownHook(
Thread {
close("Netty4 Server") { server.cancel() }
},
)
server.await()
}
and then through the magic of Guice, I get to something like this
@Service(APPLICATION_NAME)
class EchoActivity : Activity() {
@Operation("Echo")
fun echo(input: EchoInput): EchoOutput {
return EchoOutput
.builder()
.withString(input.string)
.build()
}
}
A few of the alternatives I found were:
1. Ensuring main
is runBlocking(Dispachers.Default)
-> this can be done but it doesn't eventually impact the EchoActivity, as it isn't called directly from the main
function.
2. Creating a global variable like val COROUTINE_SCOPE = CoroutineScope(Dispatchers.Default + SupervisorJob())
with a shutdown hook next to the server and then just use it everywhere to manage all the requests
Does any of this track with you? I've been doing some tests (basically spamming this Echo) and I'm not getting what I expect - a lot of single threaded/single coroutine usage