Hello, I have got some problems to make a small prototype of mine run
smoothly.
I want to send a token (type Integer) around a circle of fibers, each
fiber hands the message, decreased by one on to the next fiber via
publishing it to its MemoryChannel (called "Out"). The next fiber has
subscribed to that channel. So it's a linked, circular list. A fairly
standard example, I suppose.
My code is here:
https://github.com/kaeluka/Jetlang-Ring/
(look in ring/RingElem.java for the implementation of the Item that
passes the token on to the next one)
As you can see, there is a
"private static PoolFiberFactory factory" -- if I use a fiber that is
generated from that factory, my program runs like expected: the token
gets passed around and once it reaches zero, the JVM terminates
(because of the System.exit).
Now to the problem:
If I use a ThreadFiber instead of a Factory-generated Fiber, the
program runs for a couple of lines of output and then suddenly
*terminates*. The number of successful transmissions is different
every time I run it (and I have to feeling that it might depend on
your hardware, too).
The output looks like this:
.../Jetlang-Ring $ make run
javac -g ring/RingElem.java
java proto
RingElem 1 received 500000
RingElem 2 received 499999
RingElem 3 received 499998
RingElem 4 received 499997
RingElem 5 received 499996
RingElem 6 received 499995
RingElem 7 received 499994
RingElem 8 received 499993
RingElem 9 received 499992
RingElem 10 received 499991
RingElem 11 received 499990
RingElem 12 received 499989
RingElem 13 received 499988
RingElem 14 received 499987
.../Jetlang-Ring $
so I guess, all threads have died? Since none of them was a daemon and
the JVM exited? But why? Debugging did not get me far, sadly, but that
might be attributed to myself; I'm a relative beginner to OOP
concurrency and didn't use java in years..