Thanks Christian.

Since the calculating thread is held between each result, if you stop
calling next() on the iterator it effectively suspends the calculation
process.

When the iterator drops out of scope if becomes eligible for
collection. On finalize() it interrupts the collecting thread
associated with it. I've written tests to make sure the threads get
cleared on garbage collection following incomplete reads.

If you don't want to wait for GC, you can call dispose() on the
iterators (provided you use their concrete type
YieldAdapterIterator<T>). This might be necessary if you had thousands
of semi-complete calculations as a lack of threads is not going to
trigger GC in the way lack of memory would. Alternatively you could
call System.gc() manually.

Jim

2008/10/13 Christian Catchpole <[EMAIL PROTECTED]>:
>
> Cool.  I have become a real fan of iterators.  Can you interrupt the
> calculating function?  What happens if you throw away the iterator
> without fully iterating it?  Will the thread block forever or does
> finalize clean it up?
>
> On Oct 13, 7:20 am, "Jim Blackler" <[EMAIL PROTECTED]> wrote:
>> Hello all
>>
>> I've just finished a little library and article about my efforts to
>> emulate a form of C#'s yield return in Java.
>>
>> It uses a new thread and a SynchronousQueue object to enable any
>> calculating function to return its output through a standard Java
>> iterator.
>>
>> The post is here ..http://jimblackler.net/blog/?p=61
>>
>> I'd be interested in any views.
>>
>> Jim
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to