I'm trying to asynchronously read files and wrap it inside a coroutine
That part I got working with AsynchronousFileChannel, but if you try and use AsynchronousFileChannel for files that are inside a jar file (src/main/resources), it throws an UnsupportedException
What are the options for asynchronously reading files from inside a JAR other than literally copying all the files out of the JAR on startup and reading it asynchronously from the file system?
e
ephemient
05/21/2022, 10:55 AM
do you have resources where this matters? I think there's a basic assumption that everything in jars is "fast enough" - e.g. just a normal function call can result in class loading which is synchronous
j
janvladimirmostert
05/21/2022, 11:03 AM
I'm bundling a "static" web application inside the JAR and under load, the usual
javaClass.getResourceAsStream(...)?.use { inputStream -> ... }
causes a bottleneck.
What I've done before is to read those files into a hashmap into memory on the first read, but when it's a lot of files, then it's starting to use up memory unnecessarily, so I've started looking into AsynchronousFileChannel
Having the web application inside the JAR and served by the same backend that's handling the POST requests has quite a few benefits like not having to deal with CORS