Effectively final

blackbelt1999 blackbelt1999 at sbcglobal.net
Wed Sep 14 13:16:40 PDT 2011


OOPS! I see "Runnable" but I read "Thread".





________________________________
From: Steven Simpson <ss at comp.lancs.ac.uk>
To: lambda-dev at openjdk.java.net
Sent: Wed, September 14, 2011 12:49:29 PM
Subject: Re: Effectively final

On 14/09/11 19:46, blackbelt1999 wrote:
> Is there not a fundamental difference between the original code and 
> the new code, namely the original code creates a new thread of 
> execution while the new code does not?

Neither version creates a new thread.  The creation of a Runnable does 
not imply the creation of a new thread.

> >>      void foo(final Socket socket) {
> >>        new Runnable() {
> >>          boolean timedOut;
> >>          public void run() {
> >>            system.setTimeout(100, #{ timedOut = true; });
> >>            socket.onData(#{ if (!timedOut) System.out.println("Got 
> data"); });
> >>          }
> >>        }.run();
> >>      }


More information about the lambda-dev mailing list