5 ms·
Java is getting green threads/fibers by means of project Loom. Arguably much more straightforward to use compared to async/await.
by apta 7y ago
Java is getting green threads/fibers by means of project Loom. Arguably much more straightforward to use compared to async/await.
- ksec 7y agoSo when is this Project Loom set to arrive?
- fnord123 7y agoLiterally "when it's done". This is the answer given in talks by the developers working on it. But you have to understand that many many libraries are on Java 1.8 because that's what Android supports. Even when Loom arrives, many libraries won't use it but will rather continue to use threads.
- thu2111 7y agoBut that's the nice thing about Loom. The direction they're heading in is upgrading the existing Java threading APIs. Maybe not "new Thread() {}" but if you use ForkJoinPool, executors, etc then it should mostly all just work. That means it won't fork the ecosystem in the same way Kotlin coroutines do (coloured functions in new languages). And even better it won't fork the ecosystem across Android either. If you use constructs that don't automatically Loomify, you can just tweak them so they still work fine on Android but get the benefits of Loom too. BTW parts of Loom already shipped. On the other hand, outside of certain core libraries this won't matter much. You don't do a whole lot of scalable blocking IO on phones.
- fnord123 7y ago>Maybe not "new Thread() {}" but if you use ForkJoinPool, executors, etc then it should mostly all just work. Ah that's a nice way to do it. But then what happens to Channels? Are they cast aside so we go back to InputStream which blocks the fiber? > You don't do a whole lot of scalable blocking IO on phones. No but you can save a lot of memory, a lot of context switches, and CPU depending on the scenario.
- thu2111 7y agoI'm not sure but yeah, in theory you don't need more than Input/OutputStreams if you can block at will.