| From | Sent On | Attachments |
|---|---|---|
| Neal Gafter | Feb 7, 2010 9:10 am | |
| John Nilsson | Feb 7, 2010 2:50 pm | |
| Neal Gafter | Feb 7, 2010 3:36 pm | |
| John Nilsson | Feb 8, 2010 9:20 am | |
| Neal Gafter | Feb 8, 2010 11:03 am | |
| John Nilsson | Feb 8, 2010 2:44 pm | |
| Neal Gafter | Feb 8, 2010 3:34 pm | |
| John Rose | Feb 9, 2010 11:21 am | |
| John Nilsson | Feb 9, 2010 12:21 pm | |
| John Nilsson | Feb 9, 2010 12:50 pm | |
| Neal Gafter | Feb 9, 2010 1:05 pm | |
| John Nilsson | Feb 9, 2010 1:51 pm | |
| Neal Gafter | Feb 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





