SlideShare a Scribd company logo
1 of 99
Download to read offline
Concurrency in the Java Language and Platform

               Fredrik Öhrström
     Principal Member of Technical Staff
                      JRockit+Hotspot




                                 .   .    .     .   .   .
Concurrency in the Java Language and Platform

                        Fredrik Öhrström
              Principal Member of Technical Staff
                               JRockit+Hotspot

I have worked on the JRockit JVM for the last 6 six years and on
               the OpenJDK during the last year.
                    Thus I am bi-jvm-lingual.
           I am now working in the language team led
          by the Java Language Architect Brian Goetz.
Though I am currently sidetracked to rewrite the build system for
                           OpenJDK.


                                           .    .    .   .    .     .
The following is intended to outline our general product direction.
It is intended for information purposes only, and may not be
incorporated into any contract. It is not a commitment to deliver
any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and
timing of any features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.




                                             .    .   .    .    .     .
In the beginning



       In 1974, Donald Knuth wrote a paper with the title
       Structured Programming with goto statements.




                                             .    .    .    .   .   .
In the beginning



       In 1974, Donald Knuth wrote a paper with the title
       Structured Programming with goto statements.
       “In the late 1960s we witnessed a ’software crisis,’ which
       many people thought paradoxical because programming was
       supposed to be easy.”




                                             .    .    .    .   .   .
In the beginning



       In 1974, Donald Knuth wrote a paper with the title
       Structured Programming with goto statements.
       “In the late 1960s we witnessed a ’software crisis,’ which
       many people thought paradoxical because programming was
       supposed to be easy.”
       It then takes him approx 60 pages to discuss the problems
       with for-loops that were relevant at the time.




                                              .   .    .    .      .   .
In the beginning



       In 1974, Donald Knuth wrote a paper with the title
       Structured Programming with goto statements.
       “In the late 1960s we witnessed a ’software crisis,’ which
       many people thought paradoxical because programming was
       supposed to be easy.”
       It then takes him approx 60 pages to discuss the problems
       with for-loops that were relevant at the time.
       Today, it is even more complicated!




                                              .   .    .    .      .   .
double highestScore = 0.0;
for (Student s : students) {
  if (s.gradYear == 2010) {
    if (s.score > highestScore) {
      highestScore = s.score;
    }
  }
}




                                    .   .   .   .   .   .
double highestScore = 0.0;
for (Student s : students) {
  if (s.gradYear == 2010) {
    if (s.score > highestScore) {
      highestScore = s.score;
    }
  }
}

   Traversal logic is encoded into bytecode.




                                           .   .   .   .   .   .
double highestScore = 0.0;
for (Student s : students) {
  if (s.gradYear == 2010) {
    if (s.score > highestScore) {
      highestScore = s.score;
    }
  }
}

   Traversal logic is encoded into bytecode.
   Business logic is stateful.




                                           .   .   .   .   .   .
double highestScore = 0.0;
for (Student s : students) {
  if (s.gradYear == 2010) {
    if (s.score > highestScore) {
      highestScore = s.score;
    }
  }
}

   Traversal logic is encoded into bytecode.
   Business logic is stateful.
   Existing collections impose external iteration



                                            .       .   .   .   .   .
double highestScore = 0.0;
for (Student s : students) {
  if (s.gradYear == 2010) {
    if (s.score > highestScore) {
      highestScore = s.score;
    }
  }
}

   Traversal logic is encoded into bytecode.
   Business logic is stateful.
   Existing collections impose external iteration
   For complex datasets the iterator becomes unnecessary
   complex.

                                            .       .   .   .   .   .
This might sound like a theoretical exercise, but Oracle is affected
by the lack of concurrency in Javac, right at this very moment.




                                             .    .    .   .    .     .
.   .   .   .   .   .
.   .   .   .   .   .
.   .   .   .   .   .
.   .   .   .   .   .
.   .   .   .   .   .
Developers need easy to use parallel libraries



       One of Java’s strengths has always been its libraries
       Ideally the library should decide which strategy to use to
       decompose the problem into parallel parts.
       Obvious places are the collection classes, add parallel: filter,
       sort, map/reduce, select, collect, detect, reject




                                                 .    .   .    .    .    .
Developers need easy to use parallel libraries



       One of Java’s strengths has always been its libraries
       Ideally the library should decide which strategy to use to
       decompose the problem into parallel parts.
       Obvious places are the collection classes, add parallel: filter,
       sort, map/reduce, select, collect, detect, reject
       Why don’t we see more parallel libraries today?




                                                 .    .   .    .    .    .
Without more language support for
parallel idioms, people will
instinctively reach for serial idioms.




                           .   .   .   .   .   .
Internal iteration (functional approach)
   double highestScore =
     students.filter(new Predicate<Student>() {
       public boolean op(Student s) {
         return s.gradYear == 2010;
       }
     }).map(new Extractor<Student,Double>() {
       public Double extract(Student s) {
         return s.score;
       }
     }).max();




                                       .   .   .   .   .   .
Internal iteration (functional approach)
   double highestScore =
     students.filter(new Predicate<Student>() {
       public boolean op(Student s) {
         return s.gradYear == 2010;
       }
     }).map(new Extractor<Student,Double>() {
       public Double extract(Student s) {
         return s.score;
       }
     }).max();
       Not inherently serial.




                                       .   .   .   .   .   .
Internal iteration (functional approach)
   double highestScore =
     students.filter(new Predicate<Student>() {
       public boolean op(Student s) {
         return s.gradYear == 2010;
       }
     }).map(new Extractor<Student,Double>() {
       public Double extract(Student s) {
         return s.score;
       }
     }).max();
       Not inherently serial.
       Traversal logic completely inside collection.



                                                .      .   .   .   .   .
Internal iteration (functional approach)
   double highestScore =
     students.filter(new Predicate<Student>() {
       public boolean op(Student s) {
         return s.gradYear == 2010;
       }
     }).map(new Extractor<Student,Double>() {
       public Double extract(Student s) {
         return s.score;
       }
     }).max();
       Not inherently serial.
       Traversal logic completely inside collection.
       Stateless!


                                                .      .   .   .   .   .
Internal iteration (functional approach)
   double highestScore =
     students.filter(new Predicate<Student>() {
       public boolean op(Student s) {
         return s.gradYear == 2010;
       }
     }).map(new Extractor<Student,Double>() {
       public Double extract(Student s) {
         return s.score;
       }
     }).max();
       Not inherently serial.
       Traversal logic completely inside collection.
       Stateless!
       Can be done in parallel!
                                                .      .   .   .   .   .
The noise, the noise
   double highestScore =
     students.filter(new Predicate<Student>() {
       public boolean op(Student s) {
         return s.gradYear == 2010;
       }
     }).map(new Extractor<Student,Double>() {
       public Double extract(Student s) {
         return s.score;
       }
     }).max();
       Not inherently serial.
       Traversal logic completely inside collection.
       Stateless!
       Can be done in parallel!
                                                .      .   .   .   .   .
Lambda Expressions




                     .   .   .   .   .   .
Code as data?


   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();




                                      .   .     .   .   .   .
Code as data?


   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      An -> identifies a lambda expression




                                            .   .   .   .   .   .
Code as data?


   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      An -> identifies a lambda expression
      Target type parameters




                                            .   .   .   .   .   .
Code as data?


   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      An -> identifies a lambda expression
      Target type parameters
      More than one parameter (a,b)->c




                                            .   .   .   .   .   .
Code as data?


   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      An -> identifies a lambda expression
      Target type parameters
      More than one parameter (a,b)->c
      Body may be an expression or {statements}




                                            .     .   .   .   .   .
Code as data?

   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      Code reads like the problem statement: Find the highest score
      of the students who graduated in 2010”




                                             .   .    .    .   .      .
Code as data?

   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      Code reads like the problem statement: Find the highest score
      of the students who graduated in 2010”
      Shorter than nested for loops, and potentially faster because
      the collection implementation determines how to iterate




                                              .    .   .    .    .    .
Code as data?

   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      Code reads like the problem statement: Find the highest score
      of the students who graduated in 2010”
      Shorter than nested for loops, and potentially faster because
      the collection implementation determines how to iterate
      filter() method body can exploit representation knowledge




                                              .    .   .    .    .    .
Code as data?

   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      Code reads like the problem statement: Find the highest score
      of the students who graduated in 2010”
      Shorter than nested for loops, and potentially faster because
      the collection implementation determines how to iterate
      filter() method body can exploit representation knowledge
      Opportunities for lazy evaluation in filter() and map()




                                              .    .   .       .   .   .
Code as data?

   double highestScore =
     students.filter(s -> s.gradYear == 2010)
     .map(s -> s.score)
     .max();
      Code reads like the problem statement: Find the highest score
      of the students who graduated in 2010”
      Shorter than nested for loops, and potentially faster because
      the collection implementation determines how to iterate
      filter() method body can exploit representation knowledge
      Opportunities for lazy evaluation in filter() and map()
      Opportunities for parallelism


                                              .    .   .       .   .   .
Lambda Expressions



      The name comes from the lambda calculus created by Church
      (1936)




                                          .    .   .   .    .     .
Lambda Expressions



      The name comes from the lambda calculus created by Church
      (1936)
      Later explored by Steele and Sussman (1975-1980)




                                           .    .   .    .   .    .
Lambda Expressions



      The name comes from the lambda calculus created by Church
      (1936)
      Later explored by Steele and Sussman (1975-1980)
      Thus by adding lambda expressions we have moved from 1974
      (Knuth’s structured gotos) to 1975 (Scheme and lexical
      lambdas).




                                           .    .   .    .   .    .
Lambda Expressions



      The name comes from the lambda calculus created by Church
      (1936)
      Later explored by Steele and Sussman (1975-1980)
      Thus by adding lambda expressions we have moved from 1974
      (Knuth’s structured gotos) to 1975 (Scheme and lexical
      lambdas).
      Yay!




                                           .    .   .    .   .    .
Lambda Expressions




      A lambda expression is a lexically scoped anonymous method.




                                            .   .    .   .    .     .
Lambda Expressions




      A lambda expression is a lexically scoped anonymous method.
      Lexical scoping: can read variables from the lexical
      environment, including “this”, unlike inner classes.
      No shadowing of lexical scope, unlike inner classes.
      Not a member of any class, unlike inner classes.




                                               .   .     .   .   .   .
Why were lambda expressions not added earlier to Java?




                                    .   .   .   .   .    .
Why were lambda expressions not added earlier to Java?


      After all, Steele who wrote the lambda papers in 1975, worked
      in the Java team for several years!




                                             .   .    .    .   .      .
Why were lambda expressions not added earlier to Java?


      After all, Steele who wrote the lambda papers in 1975, worked
      in the Java team for several years!
      The reason was the design decision that every memory
      allocation should be visible as a “new” in Java source code.




                                              .    .   .    .    .    .
Why were lambda expressions not added earlier to Java?


      After all, Steele who wrote the lambda papers in 1975, worked
      in the Java team for several years!
      The reason was the design decision that every memory
      allocation should be visible as a “new” in Java source code.
      And the reason for this decision was that the hardware of the
      time simply was not powerful enough.




                                              .    .   .    .    .    .
Why were lambda expressions not added earlier to Java?


      After all, Steele who wrote the lambda papers in 1975, worked
      in the Java team for several years!
      The reason was the design decision that every memory
      allocation should be visible as a “new” in Java source code.
      And the reason for this decision was that the hardware of the
      time simply was not powerful enough.
      But now we have enough hardware to be able to spend
      significant cpu power on the optimization problems and GC to
      make this less of a problem.




                                              .    .   .    .    .    .
Typing




         .   .   .   .   .   .
What is the type of a lambda expression?




   s -> s.gradYear == 2010
      Morally, a function type from Student to boolean
      But Java does not have function types....




                                             .    .      .   .   .   .
What is the type of a lambda expression?



   s -> s.gradYear == 2010
      How would we write a function type?
      How would it interact with boxing?
      How would it interact with generics?
      How would it describe checked exceptions?
      Would it be possible to overload based on function type?




                                             .    .   .    .     .   .
In Java we use interfaces (and abstract classes) in two different
ways:




                                             .    .   .    .       .   .
In Java we use interfaces (and abstract classes) in two different
ways:
    To specify behaviour: PrintWriter.println(),
    Student.setGrade(), GraphicsObject.render().




                                             .    .   .    .       .   .
In Java we use interfaces (and abstract classes) in two different
ways:
    To specify behaviour: PrintWriter.println(),
    Student.setGrade(), GraphicsObject.render().
    To specify calling parameters and return value:
    Runnable.run(), Callable.call(), Comparator.compare(),
    ActionListener.actionPerformed(),TimerTask.run()




                                             .    .   .    .       .   .
In Java we use interfaces (and abstract classes) in two different
ways:
    To specify behaviour: PrintWriter.println(),
    Student.setGrade(), GraphicsObject.render().
    To specify calling parameters and return value:
    Runnable.run(), Callable.call(), Comparator.compare(),
    ActionListener.actionPerformed(),TimerTask.run()
We can reuse the second kind of interfaces as function types. For
backwards compatibility. When we have reified Java, then we can
more easily add real function types.




                                             .    .   .    .       .   .
Introducing SAM-types


   A SAM-type is an interface or abstract class with a Single Abstract
   Method

   interface Runnable { void run(); }
   interface Callable<T> { T call(); }
   interface Comparator<T> { boolean compare(T x, T y); }
   interface ActionListener { void actionPerformed(...);
   abstract class TimerTask { ... abstract void run(); ... }




                                               .    .    .   .    .      .
The type of a lambda expression is a SAM-type
   “SAM-conversion” infers a SAM-type for a lambda expression:

   Predicate<Student> p = s -> s.gradYear == 2010;

   Invoking the SAM-type’s method invokes the lambdas’s body

   boolean ok = p.isTrue(aStudent);

   Instant compatibility with existing libraries!

   executor.submit( ()->{ println(“Boo”); });




                                                    .   .   .   .   .   .
The type of a lambda expression is a SAM-type
   “SAM-conversion” infers a SAM-type for a lambda expression:

   Predicate<Student> p = s -> s.gradYear == 2010;

   Invoking the SAM-type’s method invokes the lambdas’s body

   boolean ok = p.isTrue(aStudent);

   Instant compatibility with existing libraries!

   executor.submit( ()->{ println(“Boo”); });

   Lambda expressions may only appear in contexts where they can
   undergo SAM conversion (assignment, method call/return, cast).

                                                    .   .   .   .   .   .
double highestScore =
  students.filter( (Student s)-> s.gradYear == 2010)
  .map((Student s)-> s.score)
  .max();

Since SAM-conversion uses target typing, the parameter types can
be left out!




                                           .   .    .   .    .     .
double highestScore =
  students.filter( (Student s)-> s.gradYear == 2010)
  .map((Student s)-> s.score)
  .max();

Since SAM-conversion uses target typing, the parameter types can
be left out!
    double highestScore =
  students.filter(s -> s.gradYear == 2010)
  .map(s -> s.score)
  .max();




                                           .   .    .   .    .     .
So, lambda expressions are just a better syntax for inner
anonymous classes? I.e. more sugar?




                                             .    .   .     .   .   .
So, lambda expressions are just a better syntax for inner
anonymous classes? I.e. more sugar?

No! They cannot be!




                                             .    .   .     .   .   .
So, lambda expressions are just a better syntax for inner
anonymous classes? I.e. more sugar?

No! They cannot be!
To understand why, we need to understand how the JVM achieves
high performance today.




                                             .    .   .     .   .   .
static class Coord {
  final int x, y;

    Coord(int xx, int yy) { x=xx; y=yy; }
    Coord add(Coord c) {
      return new Coord(x+c.x,y+c.y);
    }
    double dist(Coord c) {
      int dx = c.x-x;
      int dy = c.y-y;
      return Math.sqrt(dx*dx+dy*dy);
    }
}


                                    .   .   .   .   .   .
public static class Matrix {
  int a,b,c,d;

    public Matrix(int aa, int bb, int cc, int dd) {
      a = aa; b = bb; c = cc; d = dd;
    }
    public static Matrix scaler(int k) {
      return new Matrix(k,0,0,k);
    }
    public Matrix mul(int k) {
      return new Matrix(a*k,b*k,c*k,d*k);
    }
    Coord mul(Coord co) {
      return new Coord(co.x*a+co.y*c,co.x*b+co.y*d);
    }
}
                                     .   .   .   .     .   .
Calculation


              [           ]         ] [
                                    [        ] [    ]
                  33 0            k      22      dx
                              ×2×    −        =
                   0 33           k      11      dy
                                  √
                          answer = dx2 + dy2




                                            .   .   .   .   .   .
Calculation


              [           ]         ] [
                                    [        ] [    ]
                  33 0            k      22      dx
                              ×2×    −        =
                   0 33           k      11      dy
                                  √
                          answer = dx2 + dy2

   public static double test(int k) {
     return Matrix.scaler(33).mul(2).mul(new Coord(k,k))
               .dist(new Coord(22,11));
   }




                                            .   .   .   .   .   .
Calculation


   public static void main(String... args) {
     int i=0;
     double d = 0;
     for (;;) {
       d = test(4711);
       if (++i > 1000000) {
         System.out.println("+d);
         i=0;
       }
     }
   }



                                      .   .    .   .   .   .
.   .   .   .   .   .
x86_sub   esp ← esp 4
x86_mov   edi ← eax
x86_test *[0xb722f000] eax
x86_imul eax ← eax 66
x86_imul edi ← edi 66
x86_mov   ecx ← 22
x86_sub   ecx ← ecx eax
x86_mov   esi ← 11
x86_sub   esi ← esi edi
x86_imul ecx ← ecx ecx
x86_imul esi ← esi esi
x86_add   ecx ← ecx esi
x86_cvtsi2sd xmm0 ← ecx
x86_sqrtsd   xmm0 ← xmm0
x86_pop      ecx esp ← esp
x86_retxmm0 esp
                             .   .   .   .   .   .
Inlining implies great optimization opportunities




                                       .   .   .    .   .   .
But where to inline when using multiple cores?




                                     .   .   .   .   .   .
.   .   .   .   .   .
Fortunately a new JVM technology called the MethodHandle
is available for us.
A MethodHandle is (among many things) a root for inlining
that require no function!
A MethodHandle will be hidden behind the SAM-type
interface.
It can express new code using objects on the Java heap.




                                       .   .    .    .    .   .
Fortunately a new JVM technology called the MethodHandle
is available for us.
A MethodHandle is (among many things) a root for inlining
that require no function!
A MethodHandle will be hidden behind the SAM-type
interface.
It can express new code using objects on the Java heap.
This code can be efficiently optimized.




                                        .   .   .    .    .   .
Assume an interface to extract a value from an object:

interface Extractor<T, U> { U get(T element); }

And a new sort method on Collections using the Extractor:

public <T, U extends Comparable<...>>
void sortBy(Collection<T> coll, Extractor<T,U> ex) {...}

Then, pass a lambda expression that “wraps” a method call:

Collections.sortBy(people, p -> p.getLastName() );


    SAM conversion types the lambda as
    Extractor<Person,String>
    sortBy() can pre-query last names, cache them, build indices...
                                            .    .    .   .    .      .
Is that the best we can do?


   Collections.sortBy(people, p -> p.getLastName() );

   Writing little wrapper lambdas will be a pain!
   Lets reference a method directly!

   Collections.sortBy(people, Person#getLastName );


       Method reference introduced with # (not locked down yet!)
       No need for () or parameter types in simple cases




                                                .   .      .   .   .   .
Another very common use case!




   To bind user interface callbacks to your code:
   save_button.addActionListener(this#save);




                                           .   .    .   .   .   .
Another very common use case!




   To bind user interface callbacks to your code:
   save_button.addActionListener(this#save);
   Or even shorter:
   save_button.addActionListener(#save);




                                           .   .    .   .   .   .
Recap



        When code outgrows a lambda expression, write a method
        and take a method reference
        Lambda expressions and method references have SAM types
        Work easily with existing libraries
        Can specify parameter types explicitly if needed
        Three kinds of method references (unbound/bound/static)
        No field references (use method references to getters/setters)




                                                .    .     .   .   .    .
Wrap up




          .   .   .   .   .   .
Collections.sort(people, new Comparator<Person>() {
  public int compare(Person x, Person y) {
    return x.getLastName().compareTo(y.getLastName());
  }
});




                                    .   .   .   .   .    .
Collections.sort(people, new Comparator<Person>() {
  public int compare(Person x, Person y) {
    return x.getLastName().compareTo(y.getLastName());
  }
});

Collections.sort(people, (Person x, Person y)->
    x.getLastName().compareTo(y.getLastName()) );




                                    .   .   .   .   .    .
Collections.sort(people, new Comparator<Person>() {
  public int compare(Person x, Person y) {
    return x.getLastName().compareTo(y.getLastName());
  }
});

Collections.sort(people, (Person x, Person y)->
    x.getLastName().compareTo(y.getLastName()) );

Collections.sortBy(people, (Person p)-> p.getLastName() );




                                    .   .   .   .   .    .
Collections.sort(people, new Comparator<Person>() {
  public int compare(Person x, Person y) {
    return x.getLastName().compareTo(y.getLastName());
  }
});

Collections.sort(people, (Person x, Person y)->
    x.getLastName().compareTo(y.getLastName()) );

Collections.sortBy(people, (Person p)-> p.getLastName() );

Collections.sortBy(people,   p -> p.getLastName() );




                                    .   .   .   .   .    .
Collections.sort(people, new Comparator<Person>() {
  public int compare(Person x, Person y) {
    return x.getLastName().compareTo(y.getLastName());
  }
});

Collections.sort(people, (Person x, Person y)->
    x.getLastName().compareTo(y.getLastName()) );

Collections.sortBy(people, (Person p)-> p.getLastName() );

Collections.sortBy(people,   p -> p.getLastName() );

Collections.sortBy(people, Person#getLastName);

                                    .   .   .   .   .    .
.   .   .   .   .   .
Lambda expressions




                     .   .   .   .   .   .
Lambda expressions - More concise




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract
Type inference




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract
Type inference - Less ceremony




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract
Type inference - Less ceremony
Method references




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract
Type inference - Less ceremony
Method references - More reuse




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract
Type inference - Less ceremony
Method references - More reuse
JVM support




                                    .   .   .   .   .   .
Lambda expressions - More concise
Better libraries - More abstract
Type inference - Less ceremony
Method references - More reuse
JVM support - More performance




                                    .   .   .   .   .   .
Thanks!




          .   .   .   .   .   .

More Related Content

What's hot

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsFALLEE31188
 
Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesRobert Lujo
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingGarth Gilmour
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceOUM SAOKOSAL
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3mohamedsamyali
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うbpstudy
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4mohamedsamyali
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with framelessMiguel Pérez Pasalodos
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
Declarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesDeclarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesEelco Visser
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classesKumar
 

What's hot (20)

Java OO Revisited
Java OO RevisitedJava OO Revisited
Java OO Revisited
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
SOLID Ruby SOLID Rails
SOLID Ruby SOLID RailsSOLID Ruby SOLID Rails
SOLID Ruby SOLID Rails
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Object.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examplesObject.__class__.__dict__ - python object model and friends - with examples
Object.__class__.__dict__ - python object model and friends - with examples
 
03class
03class03class
03class
 
Xtext Eclipse Con
Xtext Eclipse ConXtext Eclipse Con
Xtext Eclipse Con
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 
Java Basics - Part1
Java Basics - Part1Java Basics - Part1
Java Basics - Part1
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
C# Summer course - Lecture 3
C# Summer course - Lecture 3C# Summer course - Lecture 3
C# Summer course - Lecture 3
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with frameless
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Object calisthenics
Object calisthenicsObject calisthenics
Object calisthenics
 
Declarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesDeclarative Name Binding and Scope Rules
Declarative Name Binding and Scope Rules
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Php object orientation and classes
Php object orientation and classesPhp object orientation and classes
Php object orientation and classes
 

Viewers also liked

Viewers also liked (20)

Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 
Literate Programming
Literate ProgrammingLiterate Programming
Literate Programming
 
Context Clues
Context CluesContext Clues
Context Clues
 
Context Clues
Context CluesContext Clues
Context Clues
 
Context Clues
Context CluesContext Clues
Context Clues
 
Context clues
Context cluesContext clues
Context clues
 
Java basic
Java basicJava basic
Java basic
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Hum1020 fa2014 exam 4 study guide
Hum1020 fa2014 exam 4 study guideHum1020 fa2014 exam 4 study guide
Hum1020 fa2014 exam 4 study guide
 
New Realism
New RealismNew Realism
New Realism
 
Hum2220 sm2015 syllabus
Hum2220 sm2015 syllabusHum2220 sm2015 syllabus
Hum2220 sm2015 syllabus
 
Tausug beliefs and practices
Tausug beliefs and practicesTausug beliefs and practices
Tausug beliefs and practices
 
Hirsch rv lpm
Hirsch rv lpmHirsch rv lpm
Hirsch rv lpm
 
Eerste sessie ondernemersforum Unizo 21 01-2014
Eerste sessie ondernemersforum Unizo 21 01-2014Eerste sessie ondernemersforum Unizo 21 01-2014
Eerste sessie ondernemersforum Unizo 21 01-2014
 
W Jbrochure
W JbrochureW Jbrochure
W Jbrochure
 
e brochure
e brochuree brochure
e brochure
 
Hum2310 sp2015 syllabus
Hum2310 sp2015 syllabusHum2310 sp2015 syllabus
Hum2310 sp2015 syllabus
 
Arth2051 sp2015 syllabus
Arth2051 sp2015 syllabusArth2051 sp2015 syllabus
Arth2051 sp2015 syllabus
 
Italia sicilia
Italia   siciliaItalia   sicilia
Italia sicilia
 

Similar to Java Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom

JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 FallJavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 FallYuichi Sakuraba
 
Project Lambda: To Multicore and Beyond
Project Lambda: To Multicore and BeyondProject Lambda: To Multicore and Beyond
Project Lambda: To Multicore and BeyondDmitry Buzdin
 
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...Pôle Systematic Paris-Region
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
Secrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API DesignSecrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API DesignBrandon Satrom
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N yearsRuslan Shevchenko
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design PatternsTrevorBurnham
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?Chuk-Munn Lee
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java ProgrammingKaty Allen
 
Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?ColdFusionConference
 
Performance #5 cpu and battery
Performance #5  cpu and batteryPerformance #5  cpu and battery
Performance #5 cpu and batteryVitali Pekelis
 

Similar to Java Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom (20)

JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 FallJavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
JavaOne報告会 Java SE/JavaFX 編 - JJUG CCC 2010 Fall
 
Project Lambda: To Multicore and Beyond
Project Lambda: To Multicore and BeyondProject Lambda: To Multicore and Beyond
Project Lambda: To Multicore and Beyond
 
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Secrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API DesignSecrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API Design
 
Programming Languages: some news for the last N years
Programming Languages: some news for the last N yearsProgramming Languages: some news for the last N years
Programming Languages: some news for the last N years
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
CoffeeScript Design Patterns
CoffeeScript Design PatternsCoffeeScript Design Patterns
CoffeeScript Design Patterns
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
 
6-TDD
6-TDD6-TDD
6-TDD
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
Bosco r users2013
Bosco r users2013Bosco r users2013
Bosco r users2013
 
Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?
 
Performance #5 cpu and battery
Performance #5  cpu and batteryPerformance #5  cpu and battery
Performance #5 cpu and battery
 
Computer Scientists Retrieval - PDF Report
Computer Scientists Retrieval - PDF ReportComputer Scientists Retrieval - PDF Report
Computer Scientists Retrieval - PDF Report
 

More from JAX London

Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...JAX London
 
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...JAX London
 
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark LittleKeynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark LittleJAX London
 
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...JAX London
 
Spring Day | Behind the Scenes at Spring Batch | Dave Syer
Spring Day | Behind the Scenes at Spring Batch | Dave SyerSpring Day | Behind the Scenes at Spring Batch | Dave Syer
Spring Day | Behind the Scenes at Spring Batch | Dave SyerJAX London
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenJAX London
 
Spring Day | Identity Management with Spring Security | Dave Syer
Spring Day | Identity Management with Spring Security | Dave SyerSpring Day | Identity Management with Spring Security | Dave Syer
Spring Day | Identity Management with Spring Security | Dave SyerJAX London
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffJAX London
 
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver GierkeSpring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver GierkeJAX London
 
Keynote | The Rise and Fall and Rise of Java | James Governor
Keynote | The Rise and Fall and Rise of Java | James GovernorKeynote | The Rise and Fall and Rise of Java | James Governor
Keynote | The Rise and Fall and Rise of Java | James GovernorJAX London
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJAX London
 
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...JAX London
 
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...JAX London
 
Java Tech & Tools | Social Media in Programming in Java | Khanderao Kand
Java Tech & Tools | Social Media in Programming in Java | Khanderao KandJava Tech & Tools | Social Media in Programming in Java | Khanderao Kand
Java Tech & Tools | Social Media in Programming in Java | Khanderao KandJAX London
 
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Just Keep Passing the Message | Russel WinderJava Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Just Keep Passing the Message | Russel WinderJAX London
 
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJava Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJAX London
 
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...JAX London
 
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Modular EJBs for Enterprise OSGi | Tim WardJava EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Modular EJBs for Enterprise OSGi | Tim WardJAX London
 
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan GallimoreJava EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan GallimoreJAX London
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...JAX London
 

More from JAX London (20)

Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
Java Tech & Tools | Continuous Delivery - the Writing is on the Wall | John S...
 
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
Java Tech & Tools | Mapping, GIS and Geolocating Data in Java | Joachim Van d...
 
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark LittleKeynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
Keynote | Middleware Everywhere - Ready for Mobile and Cloud | Dr. Mark Little
 
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
Spring Day | WaveMaker - Spring Roo - SpringSource Tool Suite: Choosing the R...
 
Spring Day | Behind the Scenes at Spring Batch | Dave Syer
Spring Day | Behind the Scenes at Spring Batch | Dave SyerSpring Day | Behind the Scenes at Spring Batch | Dave Syer
Spring Day | Behind the Scenes at Spring Batch | Dave Syer
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
 
Spring Day | Identity Management with Spring Security | Dave Syer
Spring Day | Identity Management with Spring Security | Dave SyerSpring Day | Identity Management with Spring Security | Dave Syer
Spring Day | Identity Management with Spring Security | Dave Syer
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver GierkeSpring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
Spring Day | Data Access 2.0? Please Welcome Spring Data! | Oliver Gierke
 
Keynote | The Rise and Fall and Rise of Java | James Governor
Keynote | The Rise and Fall and Rise of Java | James GovernorKeynote | The Rise and Fall and Rise of Java | James Governor
Keynote | The Rise and Fall and Rise of Java | James Governor
 
Java Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily JiangJava Tech & Tools | OSGi Best Practices | Emily Jiang
Java Tech & Tools | OSGi Best Practices | Emily Jiang
 
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
Java Tech & Tools | Beyond the Data Grid: Coherence, Normalisation, Joins and...
 
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
Java Tech & Tools | Big Blobs: Moving Big Data In and Out of the Cloud | Adri...
 
Java Tech & Tools | Social Media in Programming in Java | Khanderao Kand
Java Tech & Tools | Social Media in Programming in Java | Khanderao KandJava Tech & Tools | Social Media in Programming in Java | Khanderao Kand
Java Tech & Tools | Social Media in Programming in Java | Khanderao Kand
 
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Just Keep Passing the Message | Russel WinderJava Tech & Tools | Just Keep Passing the Message | Russel Winder
Java Tech & Tools | Just Keep Passing the Message | Russel Winder
 
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter LedbrookJava Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
Java Tech & Tools | Grails in the Java Enterprise | Peter Ledbrook
 
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
Java Tech & Tools | Deploying Java & Play Framework Apps to the Cloud | Sande...
 
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Modular EJBs for Enterprise OSGi | Tim WardJava EE | Modular EJBs for Enterprise OSGi | Tim Ward
Java EE | Modular EJBs for Enterprise OSGi | Tim Ward
 
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan GallimoreJava EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
 
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 

Java Core | Concurrency in the Java Language and Platform | Fredrik Ohrstrom

  • 1. Concurrency in the Java Language and Platform Fredrik Öhrström Principal Member of Technical Staff JRockit+Hotspot . . . . . .
  • 2. Concurrency in the Java Language and Platform Fredrik Öhrström Principal Member of Technical Staff JRockit+Hotspot I have worked on the JRockit JVM for the last 6 six years and on the OpenJDK during the last year. Thus I am bi-jvm-lingual. I am now working in the language team led by the Java Language Architect Brian Goetz. Though I am currently sidetracked to rewrite the build system for OpenJDK. . . . . . .
  • 3. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. . . . . . .
  • 4. In the beginning In 1974, Donald Knuth wrote a paper with the title Structured Programming with goto statements. . . . . . .
  • 5. In the beginning In 1974, Donald Knuth wrote a paper with the title Structured Programming with goto statements. “In the late 1960s we witnessed a ’software crisis,’ which many people thought paradoxical because programming was supposed to be easy.” . . . . . .
  • 6. In the beginning In 1974, Donald Knuth wrote a paper with the title Structured Programming with goto statements. “In the late 1960s we witnessed a ’software crisis,’ which many people thought paradoxical because programming was supposed to be easy.” It then takes him approx 60 pages to discuss the problems with for-loops that were relevant at the time. . . . . . .
  • 7. In the beginning In 1974, Donald Knuth wrote a paper with the title Structured Programming with goto statements. “In the late 1960s we witnessed a ’software crisis,’ which many people thought paradoxical because programming was supposed to be easy.” It then takes him approx 60 pages to discuss the problems with for-loops that were relevant at the time. Today, it is even more complicated! . . . . . .
  • 8. double highestScore = 0.0; for (Student s : students) { if (s.gradYear == 2010) { if (s.score > highestScore) { highestScore = s.score; } } } . . . . . .
  • 9. double highestScore = 0.0; for (Student s : students) { if (s.gradYear == 2010) { if (s.score > highestScore) { highestScore = s.score; } } } Traversal logic is encoded into bytecode. . . . . . .
  • 10. double highestScore = 0.0; for (Student s : students) { if (s.gradYear == 2010) { if (s.score > highestScore) { highestScore = s.score; } } } Traversal logic is encoded into bytecode. Business logic is stateful. . . . . . .
  • 11. double highestScore = 0.0; for (Student s : students) { if (s.gradYear == 2010) { if (s.score > highestScore) { highestScore = s.score; } } } Traversal logic is encoded into bytecode. Business logic is stateful. Existing collections impose external iteration . . . . . .
  • 12. double highestScore = 0.0; for (Student s : students) { if (s.gradYear == 2010) { if (s.score > highestScore) { highestScore = s.score; } } } Traversal logic is encoded into bytecode. Business logic is stateful. Existing collections impose external iteration For complex datasets the iterator becomes unnecessary complex. . . . . . .
  • 13. This might sound like a theoretical exercise, but Oracle is affected by the lack of concurrency in Javac, right at this very moment. . . . . . .
  • 14. . . . . . .
  • 15. . . . . . .
  • 16. . . . . . .
  • 17. . . . . . .
  • 18. . . . . . .
  • 19. Developers need easy to use parallel libraries One of Java’s strengths has always been its libraries Ideally the library should decide which strategy to use to decompose the problem into parallel parts. Obvious places are the collection classes, add parallel: filter, sort, map/reduce, select, collect, detect, reject . . . . . .
  • 20. Developers need easy to use parallel libraries One of Java’s strengths has always been its libraries Ideally the library should decide which strategy to use to decompose the problem into parallel parts. Obvious places are the collection classes, add parallel: filter, sort, map/reduce, select, collect, detect, reject Why don’t we see more parallel libraries today? . . . . . .
  • 21. Without more language support for parallel idioms, people will instinctively reach for serial idioms. . . . . . .
  • 22. Internal iteration (functional approach) double highestScore = students.filter(new Predicate<Student>() { public boolean op(Student s) { return s.gradYear == 2010; } }).map(new Extractor<Student,Double>() { public Double extract(Student s) { return s.score; } }).max(); . . . . . .
  • 23. Internal iteration (functional approach) double highestScore = students.filter(new Predicate<Student>() { public boolean op(Student s) { return s.gradYear == 2010; } }).map(new Extractor<Student,Double>() { public Double extract(Student s) { return s.score; } }).max(); Not inherently serial. . . . . . .
  • 24. Internal iteration (functional approach) double highestScore = students.filter(new Predicate<Student>() { public boolean op(Student s) { return s.gradYear == 2010; } }).map(new Extractor<Student,Double>() { public Double extract(Student s) { return s.score; } }).max(); Not inherently serial. Traversal logic completely inside collection. . . . . . .
  • 25. Internal iteration (functional approach) double highestScore = students.filter(new Predicate<Student>() { public boolean op(Student s) { return s.gradYear == 2010; } }).map(new Extractor<Student,Double>() { public Double extract(Student s) { return s.score; } }).max(); Not inherently serial. Traversal logic completely inside collection. Stateless! . . . . . .
  • 26. Internal iteration (functional approach) double highestScore = students.filter(new Predicate<Student>() { public boolean op(Student s) { return s.gradYear == 2010; } }).map(new Extractor<Student,Double>() { public Double extract(Student s) { return s.score; } }).max(); Not inherently serial. Traversal logic completely inside collection. Stateless! Can be done in parallel! . . . . . .
  • 27. The noise, the noise double highestScore = students.filter(new Predicate<Student>() { public boolean op(Student s) { return s.gradYear == 2010; } }).map(new Extractor<Student,Double>() { public Double extract(Student s) { return s.score; } }).max(); Not inherently serial. Traversal logic completely inside collection. Stateless! Can be done in parallel! . . . . . .
  • 28. Lambda Expressions . . . . . .
  • 29. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); . . . . . .
  • 30. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); An -> identifies a lambda expression . . . . . .
  • 31. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); An -> identifies a lambda expression Target type parameters . . . . . .
  • 32. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); An -> identifies a lambda expression Target type parameters More than one parameter (a,b)->c . . . . . .
  • 33. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); An -> identifies a lambda expression Target type parameters More than one parameter (a,b)->c Body may be an expression or {statements} . . . . . .
  • 34. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); Code reads like the problem statement: Find the highest score of the students who graduated in 2010” . . . . . .
  • 35. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); Code reads like the problem statement: Find the highest score of the students who graduated in 2010” Shorter than nested for loops, and potentially faster because the collection implementation determines how to iterate . . . . . .
  • 36. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); Code reads like the problem statement: Find the highest score of the students who graduated in 2010” Shorter than nested for loops, and potentially faster because the collection implementation determines how to iterate filter() method body can exploit representation knowledge . . . . . .
  • 37. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); Code reads like the problem statement: Find the highest score of the students who graduated in 2010” Shorter than nested for loops, and potentially faster because the collection implementation determines how to iterate filter() method body can exploit representation knowledge Opportunities for lazy evaluation in filter() and map() . . . . . .
  • 38. Code as data? double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); Code reads like the problem statement: Find the highest score of the students who graduated in 2010” Shorter than nested for loops, and potentially faster because the collection implementation determines how to iterate filter() method body can exploit representation knowledge Opportunities for lazy evaluation in filter() and map() Opportunities for parallelism . . . . . .
  • 39. Lambda Expressions The name comes from the lambda calculus created by Church (1936) . . . . . .
  • 40. Lambda Expressions The name comes from the lambda calculus created by Church (1936) Later explored by Steele and Sussman (1975-1980) . . . . . .
  • 41. Lambda Expressions The name comes from the lambda calculus created by Church (1936) Later explored by Steele and Sussman (1975-1980) Thus by adding lambda expressions we have moved from 1974 (Knuth’s structured gotos) to 1975 (Scheme and lexical lambdas). . . . . . .
  • 42. Lambda Expressions The name comes from the lambda calculus created by Church (1936) Later explored by Steele and Sussman (1975-1980) Thus by adding lambda expressions we have moved from 1974 (Knuth’s structured gotos) to 1975 (Scheme and lexical lambdas). Yay! . . . . . .
  • 43. Lambda Expressions A lambda expression is a lexically scoped anonymous method. . . . . . .
  • 44. Lambda Expressions A lambda expression is a lexically scoped anonymous method. Lexical scoping: can read variables from the lexical environment, including “this”, unlike inner classes. No shadowing of lexical scope, unlike inner classes. Not a member of any class, unlike inner classes. . . . . . .
  • 45. Why were lambda expressions not added earlier to Java? . . . . . .
  • 46. Why were lambda expressions not added earlier to Java? After all, Steele who wrote the lambda papers in 1975, worked in the Java team for several years! . . . . . .
  • 47. Why were lambda expressions not added earlier to Java? After all, Steele who wrote the lambda papers in 1975, worked in the Java team for several years! The reason was the design decision that every memory allocation should be visible as a “new” in Java source code. . . . . . .
  • 48. Why were lambda expressions not added earlier to Java? After all, Steele who wrote the lambda papers in 1975, worked in the Java team for several years! The reason was the design decision that every memory allocation should be visible as a “new” in Java source code. And the reason for this decision was that the hardware of the time simply was not powerful enough. . . . . . .
  • 49. Why were lambda expressions not added earlier to Java? After all, Steele who wrote the lambda papers in 1975, worked in the Java team for several years! The reason was the design decision that every memory allocation should be visible as a “new” in Java source code. And the reason for this decision was that the hardware of the time simply was not powerful enough. But now we have enough hardware to be able to spend significant cpu power on the optimization problems and GC to make this less of a problem. . . . . . .
  • 50. Typing . . . . . .
  • 51. What is the type of a lambda expression? s -> s.gradYear == 2010 Morally, a function type from Student to boolean But Java does not have function types.... . . . . . .
  • 52. What is the type of a lambda expression? s -> s.gradYear == 2010 How would we write a function type? How would it interact with boxing? How would it interact with generics? How would it describe checked exceptions? Would it be possible to overload based on function type? . . . . . .
  • 53. In Java we use interfaces (and abstract classes) in two different ways: . . . . . .
  • 54. In Java we use interfaces (and abstract classes) in two different ways: To specify behaviour: PrintWriter.println(), Student.setGrade(), GraphicsObject.render(). . . . . . .
  • 55. In Java we use interfaces (and abstract classes) in two different ways: To specify behaviour: PrintWriter.println(), Student.setGrade(), GraphicsObject.render(). To specify calling parameters and return value: Runnable.run(), Callable.call(), Comparator.compare(), ActionListener.actionPerformed(),TimerTask.run() . . . . . .
  • 56. In Java we use interfaces (and abstract classes) in two different ways: To specify behaviour: PrintWriter.println(), Student.setGrade(), GraphicsObject.render(). To specify calling parameters and return value: Runnable.run(), Callable.call(), Comparator.compare(), ActionListener.actionPerformed(),TimerTask.run() We can reuse the second kind of interfaces as function types. For backwards compatibility. When we have reified Java, then we can more easily add real function types. . . . . . .
  • 57. Introducing SAM-types A SAM-type is an interface or abstract class with a Single Abstract Method interface Runnable { void run(); } interface Callable<T> { T call(); } interface Comparator<T> { boolean compare(T x, T y); } interface ActionListener { void actionPerformed(...); abstract class TimerTask { ... abstract void run(); ... } . . . . . .
  • 58. The type of a lambda expression is a SAM-type “SAM-conversion” infers a SAM-type for a lambda expression: Predicate<Student> p = s -> s.gradYear == 2010; Invoking the SAM-type’s method invokes the lambdas’s body boolean ok = p.isTrue(aStudent); Instant compatibility with existing libraries! executor.submit( ()->{ println(“Boo”); }); . . . . . .
  • 59. The type of a lambda expression is a SAM-type “SAM-conversion” infers a SAM-type for a lambda expression: Predicate<Student> p = s -> s.gradYear == 2010; Invoking the SAM-type’s method invokes the lambdas’s body boolean ok = p.isTrue(aStudent); Instant compatibility with existing libraries! executor.submit( ()->{ println(“Boo”); }); Lambda expressions may only appear in contexts where they can undergo SAM conversion (assignment, method call/return, cast). . . . . . .
  • 60. double highestScore = students.filter( (Student s)-> s.gradYear == 2010) .map((Student s)-> s.score) .max(); Since SAM-conversion uses target typing, the parameter types can be left out! . . . . . .
  • 61. double highestScore = students.filter( (Student s)-> s.gradYear == 2010) .map((Student s)-> s.score) .max(); Since SAM-conversion uses target typing, the parameter types can be left out! double highestScore = students.filter(s -> s.gradYear == 2010) .map(s -> s.score) .max(); . . . . . .
  • 62. So, lambda expressions are just a better syntax for inner anonymous classes? I.e. more sugar? . . . . . .
  • 63. So, lambda expressions are just a better syntax for inner anonymous classes? I.e. more sugar? No! They cannot be! . . . . . .
  • 64. So, lambda expressions are just a better syntax for inner anonymous classes? I.e. more sugar? No! They cannot be! To understand why, we need to understand how the JVM achieves high performance today. . . . . . .
  • 65. static class Coord { final int x, y; Coord(int xx, int yy) { x=xx; y=yy; } Coord add(Coord c) { return new Coord(x+c.x,y+c.y); } double dist(Coord c) { int dx = c.x-x; int dy = c.y-y; return Math.sqrt(dx*dx+dy*dy); } } . . . . . .
  • 66. public static class Matrix { int a,b,c,d; public Matrix(int aa, int bb, int cc, int dd) { a = aa; b = bb; c = cc; d = dd; } public static Matrix scaler(int k) { return new Matrix(k,0,0,k); } public Matrix mul(int k) { return new Matrix(a*k,b*k,c*k,d*k); } Coord mul(Coord co) { return new Coord(co.x*a+co.y*c,co.x*b+co.y*d); } } . . . . . .
  • 67. Calculation [ ] ] [ [ ] [ ] 33 0 k 22 dx ×2× − = 0 33 k 11 dy √ answer = dx2 + dy2 . . . . . .
  • 68. Calculation [ ] ] [ [ ] [ ] 33 0 k 22 dx ×2× − = 0 33 k 11 dy √ answer = dx2 + dy2 public static double test(int k) { return Matrix.scaler(33).mul(2).mul(new Coord(k,k)) .dist(new Coord(22,11)); } . . . . . .
  • 69. Calculation public static void main(String... args) { int i=0; double d = 0; for (;;) { d = test(4711); if (++i > 1000000) { System.out.println("+d); i=0; } } } . . . . . .
  • 70. . . . . . .
  • 71. x86_sub esp ← esp 4 x86_mov edi ← eax x86_test *[0xb722f000] eax x86_imul eax ← eax 66 x86_imul edi ← edi 66 x86_mov ecx ← 22 x86_sub ecx ← ecx eax x86_mov esi ← 11 x86_sub esi ← esi edi x86_imul ecx ← ecx ecx x86_imul esi ← esi esi x86_add ecx ← ecx esi x86_cvtsi2sd xmm0 ← ecx x86_sqrtsd xmm0 ← xmm0 x86_pop ecx esp ← esp x86_retxmm0 esp . . . . . .
  • 72. Inlining implies great optimization opportunities . . . . . .
  • 73. But where to inline when using multiple cores? . . . . . .
  • 74. . . . . . .
  • 75. Fortunately a new JVM technology called the MethodHandle is available for us. A MethodHandle is (among many things) a root for inlining that require no function! A MethodHandle will be hidden behind the SAM-type interface. It can express new code using objects on the Java heap. . . . . . .
  • 76. Fortunately a new JVM technology called the MethodHandle is available for us. A MethodHandle is (among many things) a root for inlining that require no function! A MethodHandle will be hidden behind the SAM-type interface. It can express new code using objects on the Java heap. This code can be efficiently optimized. . . . . . .
  • 77. Assume an interface to extract a value from an object: interface Extractor<T, U> { U get(T element); } And a new sort method on Collections using the Extractor: public <T, U extends Comparable<...>> void sortBy(Collection<T> coll, Extractor<T,U> ex) {...} Then, pass a lambda expression that “wraps” a method call: Collections.sortBy(people, p -> p.getLastName() ); SAM conversion types the lambda as Extractor<Person,String> sortBy() can pre-query last names, cache them, build indices... . . . . . .
  • 78. Is that the best we can do? Collections.sortBy(people, p -> p.getLastName() ); Writing little wrapper lambdas will be a pain! Lets reference a method directly! Collections.sortBy(people, Person#getLastName ); Method reference introduced with # (not locked down yet!) No need for () or parameter types in simple cases . . . . . .
  • 79. Another very common use case! To bind user interface callbacks to your code: save_button.addActionListener(this#save); . . . . . .
  • 80. Another very common use case! To bind user interface callbacks to your code: save_button.addActionListener(this#save); Or even shorter: save_button.addActionListener(#save); . . . . . .
  • 81. Recap When code outgrows a lambda expression, write a method and take a method reference Lambda expressions and method references have SAM types Work easily with existing libraries Can specify parameter types explicitly if needed Three kinds of method references (unbound/bound/static) No field references (use method references to getters/setters) . . . . . .
  • 82. Wrap up . . . . . .
  • 83. Collections.sort(people, new Comparator<Person>() { public int compare(Person x, Person y) { return x.getLastName().compareTo(y.getLastName()); } }); . . . . . .
  • 84. Collections.sort(people, new Comparator<Person>() { public int compare(Person x, Person y) { return x.getLastName().compareTo(y.getLastName()); } }); Collections.sort(people, (Person x, Person y)-> x.getLastName().compareTo(y.getLastName()) ); . . . . . .
  • 85. Collections.sort(people, new Comparator<Person>() { public int compare(Person x, Person y) { return x.getLastName().compareTo(y.getLastName()); } }); Collections.sort(people, (Person x, Person y)-> x.getLastName().compareTo(y.getLastName()) ); Collections.sortBy(people, (Person p)-> p.getLastName() ); . . . . . .
  • 86. Collections.sort(people, new Comparator<Person>() { public int compare(Person x, Person y) { return x.getLastName().compareTo(y.getLastName()); } }); Collections.sort(people, (Person x, Person y)-> x.getLastName().compareTo(y.getLastName()) ); Collections.sortBy(people, (Person p)-> p.getLastName() ); Collections.sortBy(people, p -> p.getLastName() ); . . . . . .
  • 87. Collections.sort(people, new Comparator<Person>() { public int compare(Person x, Person y) { return x.getLastName().compareTo(y.getLastName()); } }); Collections.sort(people, (Person x, Person y)-> x.getLastName().compareTo(y.getLastName()) ); Collections.sortBy(people, (Person p)-> p.getLastName() ); Collections.sortBy(people, p -> p.getLastName() ); Collections.sortBy(people, Person#getLastName); . . . . . .
  • 88. . . . . . .
  • 89. Lambda expressions . . . . . .
  • 90. Lambda expressions - More concise . . . . . .
  • 91. Lambda expressions - More concise Better libraries . . . . . .
  • 92. Lambda expressions - More concise Better libraries - More abstract . . . . . .
  • 93. Lambda expressions - More concise Better libraries - More abstract Type inference . . . . . .
  • 94. Lambda expressions - More concise Better libraries - More abstract Type inference - Less ceremony . . . . . .
  • 95. Lambda expressions - More concise Better libraries - More abstract Type inference - Less ceremony Method references . . . . . .
  • 96. Lambda expressions - More concise Better libraries - More abstract Type inference - Less ceremony Method references - More reuse . . . . . .
  • 97. Lambda expressions - More concise Better libraries - More abstract Type inference - Less ceremony Method references - More reuse JVM support . . . . . .
  • 98. Lambda expressions - More concise Better libraries - More abstract Type inference - Less ceremony Method references - More reuse JVM support - More performance . . . . . .
  • 99. Thanks! . . . . . .