Jetlang's fibers are not really fibers?

227 views
Skip to first unread message

Magnus Holm

unread,
Feb 20, 2012, 9:00:59 AM2/20/12
to jetla...@googlegroups.com
Hey folks,

It seems to me that Jetlang's fibers really aren't fibers at all. The whole of fibers is that they can be suspended/resumed in the middle of a code block. Jetlang's fibers are more like a channel where you publish Runnables, and there's thread that automatically pulls stuff from the channel and runs it.

Did I misunderstand something, or is this the case?

peter royal

unread,
Feb 20, 2012, 10:09:31 AM2/20/12
to jetla...@googlegroups.com
you have accurately described how jetlang works. 

java doesn't let you achieve what 'fiber' means in other programming contexts exactly. however, I think it's behavior is a reasonable approximation (and suspend/resume could be implemented with the boundary between Runnable's being the valid pause points). 

-pete

-- 
peter royal - (on the go)
--
You received this message because you are subscribed to the Google Groups "jetlang-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/jetlang-dev/-/0BalGIVgvhcJ.
To post to this group, send email to jetla...@googlegroups.com.
To unsubscribe from this group, send email to jetlang-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jetlang-dev?hl=en.

Winter Young

unread,
Dec 13, 2015, 2:36:14 AM12/13/15
to jetlang-dev
So this means if I blocked in a runnable, the backing thread would block, like akka, right?

Mike Rettig

unread,
Dec 13, 2015, 12:12:11 PM12/13/15
to jetla...@googlegroups.com
Jetlang is a lightweight java library. It doesn't change how threads
works in the jvm. If code executes that blocks on I/O then the thread
blocks. However, that choice is up to the developer. There are plenty
of non-blocking api's available if you don't want your thread to
block. With fibers, the easy solution is to replace the blocking call
with a channel publish. Another fiber can subscribe and process the
events asynchronously, even blocking if necessary.

If you want lightweight threads, then maybe pool fibers might be
better. Each ThreadFiber is backed by an OS thread. If it is a pool
fiber, then the fiber doesn't block a thread when it is awaiting work.
All runnables are executed by the threads in the configured thread
pool. The pool fibers are simple objects (no thread creation), so they
are lightweight and scale well. ThreadFibers and pool fibers can be
used in the same app.

https://github.com/jetlang/core/blob/master/src/main/java/org/jetlang/fibers/PoolFiberFactory.java
https://github.com/jetlang/core/blob/master/src/main/java/org/jetlang/fibers/ThreadFiber.java

Mike
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jetlang-dev...@googlegroups.com.
> To post to this group, send email to jetla...@googlegroups.com.
> Visit this group at https://groups.google.com/group/jetlang-dev.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages