Fiber is upcoming feature in Java which will offer a light weight alternative to Threads . However the question is why fibers ,one word answer to it is βmoneyβ.
Each thread created by Java corresponds to operating system thread. Creating Threads is costly as well as context switching to another thread is quite expensive. As a result in most applications thread gets blocked and servers remain underutilized. Java fibers on the other hand will be managed by JVM by its own scheduler .
If we see methods of Thread class vis-a-vis Fiber it will make the picture clearer.
Thread :
checkAccess() countStackFrames() getContextClassLoader() getId() getName() getPriority() getStackTrace() getState() getThreadGroup() getUncaughtExceptionHandler() interrupt() isAlive() isDaemon() isInterrupted() join() resume() run() setContextClassLoader() setDaemon() setName() setPriority() setUncaughtExceptionHandler() start() stop() suspend()
Fiber :
await() cancel() isAlive() isCancelled() schedule()
Creating and starting a fiber is quite straight forward
var fiber = new Fiber(() -> System.out.println("Hello from fiber"));
fiber.schedule();
In todayβs cloud computing world where applications are billed on hourly basis reducing server underutilization is top most priority of application owners and fibers will certainly help them.
Top comments (1)
Full disclosure first:
I'm the author and a maintainer of the Apache JavaFlow fork -- Tascalate JavaFlow.
The author of Fibers proposal (aka Project Loom), Ron Pressler, is the original author of Quasar, and a significant part of the Quasar functionality is Fibers.
So we are persons behind competitive OSS projects, and I may be biased, probably. But here is what I think.
The whole idea for Project Loom looks for me like promoting Quasar to JVM. Yes, it's doable. Yes, there is a prototype already. But... Is it grounded enough?
All in all, it would be great to have native JVM support for continuations. It will definitely beat performance of any existing continuations library -- even the current leader coroutines. It would be great to finally see tail-call optimizations in Java -- this will open the door for more functional-style code in Java. But Fibers, even they will be added, is not a silver bullet, and I hardly believe the idea to add them, at least that early, is justified enough. So I do not share your enthusiasm about them...