Jul 21
Please, enjoy the code and let me know what you think. The code is distributed under the new BSD license, and is available for everyone to download and definitely to comment or complain on.
Until the project’s site is made clearer, please take a look at the blog’s posts for explanations. Specifically, the post about the concept, the one about the implementation, about the library used, and about hooking into the class loader. Also, take a look at this example on the blog and many other examples in the proof-of-concept collections library built on top of the yielder feature, in the repository.
Thanks for your interest!
Liked Chaotic Java? It's free! But I also make some other things that aren't, which you might like. Like Firewall, a rule changing, turn based strategy game for iOS.
July 23rd, 2007 at 8:27 am
Hmm, to be honest I don’t really get what your lib is about. Even after inspecting the project homepage. Could you clarify this to me (and possibly publicly)?
Klaus
July 23rd, 2007 at 8:40 am
The explanation is in the blog, with previous posts to this one.
However, I agree that I should have made it clearer in the library site itself… I did a rush job there.
In the meantime (it will take a day), please take a look at this post.
July 23rd, 2007 at 8:49 am
I’ve added the links in the post, until I make it clear in the project itself. Thanks for the comment!
July 23rd, 2007 at 7:29 pm
Alright, project page is updated, so let me know if anything is missing or if more information is needed. Thanks!
July 30th, 2007 at 7:56 pm
Really cool. Here’s another thing you can do with this:
server continuations for nio applications. Currently to do ‘comet’ connections in java you need to use awkward hacks, like e.g. throwing RetryException. Whichever way you signal that you want to quit processing but not close the connection, the next time you get called on for more data, your doGet() method starts from the top again. With this, it would just continue right after your ‘pause()’-like call. How cool is that?!
July 30th, 2007 at 9:07 pm
It sounds cool but doesn’t that mean that you need to send a state to the Yielder iterator? (to tell it to retry if needed and if not to stop the iteration?)
August 7th, 2007 at 7:01 pm
Pretty cool stuff!
I think there’s one problem though: recursion. If you lift local variables to fields, you can’t have recursive methods calling ‘yield’. I believe that C# iterators share this limitation. Another one might be monitors. If one yields from a synchronized block, the locks should be freed/reaquired.
I have implemented continuations in OpenVM, and described some problems in Adding Continuations to JVM. Although a bit different, some issues might be interesting for your project as well.
August 7th, 2007 at 7:06 pm
Iulian,
Thanks for your comment! In fact, there is no recursion problem, just because recursion is impossible.
Both in C# and in my Java implementation, the method that yields the items has no parameters, thus recursion via parameters is impossible. Any other type of recursion is possible, and in fact I use a sort of “recursion” (by calling the same method, only over different yielders) in the tree and graph iterators.
Does that make sense, or did I misunderstand you?
August 10th, 2007 at 7:26 am
[...] It’s definitely been an exciting couple of weeks. Ever since I published the code for the yield-like feature (project site here) there has been a few mentions of it over other blogs (Tech Sweep, Neal Gafter’s blog, Lambda the Ultimate and even a reminder of when not to use such a framework from WarpedJavaGuy). [...]
October 12th, 2008 at 6:50 pm
[...] not the first engineer to attempt to bring yield to Java. Aviad Ben Dov’s article in 2007 http://chaoticjava.com/posts/java-yield-return-code-published/ describes a way to do this using bytecode manipulation and classloader modification. My view is [...]
January 11th, 2011 at 7:09 pm
Hello,
I’ve made my attempt to implement yield in java using annotation processiong.
You might will have a fun reviewing the approach.
Please see: http://www.nesterovsky-bros.com/weblog/2011/01/11/YieldFeatureInJavaImplemented.aspx