atom feed13 messages in net.java.openjdk.closures-devRe: related link
FromSent OnAttachments
Neal GafterFeb 7, 2010 9:10 am 
John NilssonFeb 7, 2010 2:50 pm 
Neal GafterFeb 7, 2010 3:36 pm 
John NilssonFeb 8, 2010 9:20 am 
Neal GafterFeb 8, 2010 11:03 am 
John NilssonFeb 8, 2010 2:44 pm 
Neal GafterFeb 8, 2010 3:34 pm 
John RoseFeb 9, 2010 11:21 am 
John NilssonFeb 9, 2010 12:21 pm 
John NilssonFeb 9, 2010 12:50 pm 
Neal GafterFeb 9, 2010 1:05 pm 
John NilssonFeb 9, 2010 1:51 pm 
Neal GafterFeb 9, 2010 1:54 pm 
Subject:Re: related link
From:John Nilsson (jo@milsson.nu)
Date:Feb 9, 2010 1:51:22 pm
List:net.java.openjdk.closures-dev

On Tue, Feb 9, 2010 at 10:05 PM, Neal Gafter <ne@gafter.com> wrote:

How would you do this using the macro scheme?

Given the macro I previously defined. The following would be expanded as below. But you were right, it was quite instructive. What does it mean to return concurrently? I guess the right thing to do is to change the macro to block the first thread waiting for the futures and return from there.

public Collection<Principal> getAttendees() { List<Principal> result = new ArrayList<Principal>(); forEachConcurrently(EventResponse r : getResponses(), threadPool) { if (r.mayAttend()) { Principal attendee = r.getAttendee(); synchronized (result) { result.add(attendee); } } } return result; }

public Collection<Principal> getAttendees() { List<Principal> result = new ArrayList<Principal>();

final Collection<Callable<Object>> tasks = new ArrayList<Callable<Object>>(); final Collection<Future<Object>> futures = new ArrayList<Future<Object>(); for(final EventResponse t : getResponses()) { tasks.add(Executors.callable(new Runnable(){public void run() { EventResponse r = t; //Slight bug in the macro, should be 'T retT' not just 'retT' forEachConcurrently_1234: { if (r.mayAttend()) { Principal attendee = r.getAttendee(); synchronized (result) { result.add(attendee); } } } }})); } try { futures.addAll(threadPool.invokeAll(tasks)); } catch (InterruptedException ex) {} return result; }

BR, John