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!

Related Posts with Thumbnails

11 Responses to “Java “yield return” code published”

  1. Klaus Meffert Says:

    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

  2. Avah Says:

    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.

  3. Avah Says:

    I’ve added the links in the post, until I make it clear in the project itself. Thanks for the comment!

  4. Avah Says:

    Alright, project page is updated, so let me know if anything is missing or if more information is needed. Thanks!

  5. Reinier Zwitserloot Says:

    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?!

  6. Avah Says:

    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?)

  7. Iulian Says:

    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.

  8. Avah Says:

    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?

  9. Chaotic Java » Feedback regarding Java ‘yield’ Says:

    [...] 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). [...]

  10. Jim Blackler · Bringing ‘yield return’ from C# to Java Says:

    [...] 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 [...]

  11. Vladimir Nesterovsky Says:

    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