SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
ilJUG	
  Java	
  8	
  Launch	
  Event	
  	
  
The	
  Future	
  of	
  Futures	
  
(Apr	
  2014)	
  
!
Haim Yadid - Performize-IT
About	
  Me:	
  Haim	
  Yadid
•21 Years of SW development experience
•Performance Expert
•Consulting R&D Groups
•Training: Java Performance Optimization
•Organizing : ILJUG
IL	
  JUG
•Israeli Java User Group
•Reborn at 1/14
•Meetup : http://www.meetup.com/IL-JUG
•G+: https://plus.google.com/u/0/communities/110138558454900054301
•Twitter: @il_jug
The	
  Beginning	
  of	
  Times
•Before J1.5
•Primitive life forms without Future
•Threads
•synchronization primitives
•wait / notify
•Most likely you will do it wrong
Futures	
  Introduction
•j.u.c.Future
•introduced in JDK 1.5
•jsr166 (Doug Lea)
•Together with Executors
•And many other concurrency constructs
•Part of the java.util.concurrent
What	
  is	
  a	
  Future
•A container for a result that will become
available at a later time
•Backed by a thread
•May contain a Throwable if computation
fails
What	
  is	
  a	
  Future
•Future means asynchronous
•Future does not mean non blocking
•Future does not mean reactive
The	
  ExecutorService
•Executor service is the container which
handles a future
•Has the threads which futures need.
•Part of j.u.c (Executors.newXXX)
•SingleThreadExecutor
•FixedThreadPool
•CachedThreadPool
•ScheduledThreadPool
Simplest	
  Example
ExecutorService e = Executors.newSingleThreadExecutor();

!
Future<Integer> future = e.submit(

() -> {sleep(1000);return 42;}

) ;
// do something useful ?
System.out.println(future.get());
Lambda	
  expression	
  which	
  
represents	
  a	
  
Callable<Integer>
User
Task(Callable,	
  
Runnable)
Future
Executor
What	
  Else	
  Can	
  Be	
  Done?
•So we are blocked until future is finished
•If it throw exception get will throw an
exception
•More that can be done:
!
!
!
•And thats all !
future.cancel(false) ; // cancel future if not executed yet (in queue) 

future.cancel(true); // in addition interrupt the running task

future.isCancelled(); // wether the future is cancelled.

future.idDone() // whether the future is done.
Futures	
  Pros
•Futures combined with Callables are
cheaper than threads.
•Easier to maintain.
•Async
We	
  will	
  get	
  to	
  the	
  cons…
Futures	
  Evolution	
  -­‐	
  Java	
  6
•Java 6 -jsr166x (CompletionService)
•Separation of concerns
ExecutorService e = Executors.newFixedThreadPool(10);

!
CompletionService<Integer> completionService = new ExecutorCompletionService<>(e);

!
completionService.submit(() -> {sleep(1000); return 42;}) ;

!
Future<Integer> future = completionService.take();

System.out.println(future.get()); // already completed…..
User
Future
Executor Consumer
Task
Futures	
  Evolution	
  -­‐	
  Java	
  7
•Java7 - jsr166y (Fork Join Pools)
•Has a common pool
•ForkJoinTask extends Future
•Completion ?
ForkJoinTask<Integer> task = ForkJoinPool.commonPool().
submit( () -> {

sleep(1000);

System.out.printf("done");

});
System.out.println(task.get());
complete()	
  	
  a	
  Complete	
  mess
•With the method complete you can
introduce a value before task competes.
•But
ForkJoinTask<Integer> task = ForkJoinPool.commonPool().

submit(() -> {

sleep(1000);

return 42;

});

!
sleep(10);
task.complete(43);

System.out.println(task.get());
task.complete(44);

System.out.println(task.get());
sleep(2000);

System.out.println(task.get());
43	
  
42	
  
44	
  
Nothing
•Dinosaurs are perfect
•They are big
•Powerful
•State of the art
Nothing,	
  but	
  evolution	
  
Alternatives
•Akka Futures/Scala Futures
•Scala Promises
•Twitter - Finnagle
•Guava ListenableFuture
•Groovy Dataflow concurrency (GPars)
Proper	
  Completion
•A correct way to complete a future.
•Once a future is completed it immutable
•It is IMPORTANT
Data-­‐flow	
  Concurrency
•If we have variables that can be written
to once
•We have deterministic behaviour!
•Run it a million times it will still work the
same!!!
Composition
•Looking for websites that will interest a
group of people
Get	
  Profile	
  
On	
  linked	
  in	
  
user	
  1
Find	
  intersection	
  of	
  skills
Get	
  Profile	
  
On	
  linked	
  in	
  
user	
  1
Get	
  Profile	
  
On	
  linked	
  in	
  
user	
  n
search	
  on	
  
google
Send	
  mail	
  with	
  group	
  recommendation
…….
 CompletableFuture	
  Is
•A container for a result that will become
available at a later time
•Backed by thread
•May contain a Throwable if computation
failed
CompletableFuture	
  Is
•Means asynchronous
•Does not mean non blocking
•Does not mean reactive
Is	
  Completable
•Is completed when completed!
•The result can be set once.
•Either by the task itself
•Or from outside.
Is	
  Composable
•Composable
•Lambda expression friendly
•More functional in it’s nature
CompletableFuture	
  Creation
•supplyAsync
•runAsync
import	
  java.util.concurrent.CompletableFuture;

import	
  static	
  java.util.concurrent.CompletableFuture.*;
	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f	
  =	
  supplyAsync(	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(10000);return	
  42;}

	
  	
  	
  	
  	
  	
  	
  	
  );	
  
	
  	
  	
  	
  	
  	
  	
  	
  f.join();
Runs	
  on	
  ForkJoinPool.commonPool;	
  
You	
  can	
  supply	
  an	
  executor	
  if	
  you	
  wantjoin	
  is	
  the	
  same	
  as	
  get	
  but	
  throws	
  an	
  
unchecked	
  exception	
  (hip	
  hip	
  hurray)
Construction
•new CompletableFuture();
•use complete(r) to complete it
•use completeExceptionally(t) to complete
with an exception
	
  CompletableFuture<Integer>	
  a=	
  new	
  CompletableFuture<>();
	
  a.complete(5);



	
  a.completeExceptionally(new	
  IndexOutOfBoundsException());	
  
CompletableFuture
•Implements CompletableStage
•A large set of methods (~60
•Every method is multiplied by three
•XXXX(….)
•XXXXAsync(…)
•XXXX(….,Executor x)
Future	
  -­‐>	
  CompletableFuture
•Not really possible (Cleanly)
	
  	
  	
  	
  	
  	
  	
  	
  Future<Integer>	
  future	
  =	
  ForkJoinPool.commonPool().submit(

	
   ()	
  -­‐>	
  {sleep(4000);return	
  42;}

	
  	
  	
  	
  	
  	
  	
  	
  );

!
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  brighterFuture	
  =	
  supplyAsync(()	
  -­‐>	
  {

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  try	
  {

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  future.get();

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  catch	
  (Exception	
  e1)	
  {

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  throw	
  new	
  RuntimeException(e1);

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }

	
  	
  	
  	
  	
  	
  	
  	
  });



	
  	
  	
  	
  	
  	
  	
  	
  System.out.println(brighterFuture.get());
Nasty	
  Exception	
  
handling	
  
Requires	
  
another	
  
thread….
!
thenApply
•Apply another action when result is
available
	
  	
  	
  	
  	
  	
  
CompletableFuture<Integer>	
  f	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(10000);return	
  42;});

!
CompletableFuture<Integer>	
  f2	
  =	
  	
  f.thenApply((r)	
  -­‐>	
  r*r);
CompletableFuture<Integer>	
  f2	
  =	
  	
  f.thenApplyAsync((r)	
  -­‐>	
  r*r);
CompletableFuture<Integer>	
  f2	
  =	
  	
  f.thenApplyAsync((r)	
  -­‐>	
  r*r,

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  myLowPriorityExecutor);
Handling	
  Exceptions
•exceptionally()
CompletableFuture<Integer>	
  f	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(10000);

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  if	
  (true)	
  throw	
  new	
  RuntimeException();	
  

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  return	
  42;});

!
CompletableFuture<Integer>	
  f2	
  =	
  

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  f.exceptionally((t)-­‐>	
  2).

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  thenApply((r)	
  -­‐>	
  r*r);



System.out.println(f2.get());
The	
  General	
  Case
•handle() - gets result and throwable
manipulates them
•whenComplete() - does something, pass
result through
CompletableFuture<Integer>	
  f2	
  =	
  f.handle(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (res,throwable)	
  -­‐>	
  (throwable==null)?	
  res*res	
  :	
  2);	
  

!
CompletableFuture<Integer>	
  f3	
  =	
  f.whenComplete(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (res,	
  throwable)	
  -­‐>	
  {System.out.println("done");});
Composition
•thenCompose()
•Performs another stage upon completion
•On failure stage will not be performed
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f1	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(2100);return	
  42;});

!
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f2	
  =	
  f1.thenCompose(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (v)	
  -­‐>	
  supplyAsync(()	
  -­‐>	
  {sleep(2100);return	
  v+42;}))	
  	
  ;



	
  	
  	
  	
  	
  	
  	
  	
  System.out.println(f2.get());
Combiners
•thenCombine() take both results and
apply a function on them
•thenAcceptBoth() - guess
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f1	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(2100);return	
  42;});

	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f2	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(2100);return	
  55;});

!
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f3	
  =	
  f1.thenCombine(f2,

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (r1,r2)	
  -­‐>	
  r1+r2)	
  	
  ;	
  
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Void>	
  f4	
  =	
  f1.thenAcceptBoth(f2,

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (r1,	
  r2)	
  -­‐>	
  System.out.println(r1	
  +	
  r2))	
  	
  ;

	
  	
  	
  	
  	
  	
  	
  	
  System.out.println(f3.get());
Either…
•thenApplyEither() take fastest result use
it. Discard the second one
•If exception is thrown behaviour is not
predictable
•Use case: parse fastest server result
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f1	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(2300);return	
  42;});

	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f2	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(2200);return	
  43;});

!
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<Integer>	
  f3	
  =	
  f1.applyToEither(f2,(r)	
  -­‐>	
  r	
  *	
  r);
A	
  Better	
  Either
•Hold down exceptions letting other
futures a chance to complete
	
  static<T>	
  CompletableFuture<T>

	
  holdDownExceptionally(CompletableFuture<T>f,	
  CountDownLatch	
  latch)	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  f.exceptionally((t)	
  -­‐>	
  {

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  try	
  {

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  latch.countDown();latch.await();

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  catch	
  (Exception	
  e)	
  {

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  throw	
  new	
  RuntimeException(t);

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  throw	
  new	
  RuntimeException(t);

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  }).	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  thenApply((r)	
  -­‐>	
  {latch.countDown();latch.countDown();return	
  r;});

	
  	
  	
  	
  }
A	
  Better	
  Either	
  cont
static	
  <T,U>	
  CompletableFuture<U>

myApplytoEither(CompletableFuture<T>	
  f1,	
  

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<T>	
  f2,

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Function<?	
  super	
  T,	
  U>	
  fn)	
  

	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  CountDownLatch	
  latch	
  =	
  new	
  CountDownLatch(2);	
  
	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<T>	
  f1be	
  =	
  holdDownExceptionally(f1,latch);

	
  	
  	
  	
  	
  	
  	
  	
  CompletableFuture<T>	
  f2be	
  =	
  holdDownExceptionally(f2,latch);	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  f1be.applyToEither(f2be,fn);

}
How	
  Many?
•A completable future may have more than
one dependents
•Use getNumberOfDependents to get an
estimate
CompletableFuture<Integer>	
  f	
  =	
  supplyAsync(

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  ()	
  -­‐>	
  {sleep(10000);return	
  42;});

!
CompletableFuture<Integer>	
  f2	
  =	
  	
  f.thenApply((r)	
  -­‐>	
  r*r);

CompletableFuture<Integer>	
  f3	
  =	
  	
  f.thenApply((r)	
  -­‐>	
  r*r*r);

CompletableFuture<Integer>	
  f4	
  =	
  	
  f.thenApply((r)	
  -­‐>	
  r*r*r*r);

!
f.getNumberOfDependents();	
  	
  	
  //	
  returns	
  3
Helper	
  Static	
  Functions
•allOf(CompletableFuture<?>... cfs)
•no value returned
•anyOf(CompletableFuture<?>... cfs)
•object retured
NIO	
  Non	
  blocking	
  IO
•Selectors
•dispatchers
•Reactor pattern
•There is no support out of the box for
CompletableFutures in NIO
What	
  about	
  J7	
  NIO2
•AsynchronousFileChannel
•AsynchronousServerSocketChannel
•Are using futures
•Not adapted for completable futures.
AsynchronousFileChannel	
  afc	
  =	
  	
  	
  

	
  	
  	
  	
  	
  	
  AsynchronousFileChannel.open(Paths.get(“Video.avi"),	
  	
  	
  	
  

	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  StandardOpenOption.READ)	
  	
  	
  ;	
  


ByteBuffer	
  r	
  =	
  ByteBuffer.allocate(500*1024*1024)	
  ;

	
  Future<Integer>	
  a	
  =	
  afc.read(r,10*1024*1024);	
  	
  	
  
//do	
  something	
  useful	
  while	
  waiting	
  	
  
a.get();	
  	
  	
  
Further	
  Info
•All examples can be found in github
•https://github.com/lifey/compfut.git
•Concurrency Interest Mailing List
•Java Concurrency in Practice(Brian Goatz)
•http://www.slideshare.net/kojilin/
completable-future
Thanks + Q&A + Contact Me
© Copyright Performize-IT LTD.
http://il.linkedin.com/in/haimyadid
lifey@performize-it.com
www.performize-it.com
blog.performize-it.com
https://github.com/lifey
@lifeyx

Más contenido relacionado

La actualidad más candente

Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot NetNeeraj Kaushik
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in JavaYakov Fain
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Martin Toshev
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaFabio Collini
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Libraryasync_io
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Jiayun Zhou
 
Fork and join framework
Fork and join frameworkFork and join framework
Fork and join frameworkMinh Tran
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 
Advanced task management with Celery
Advanced task management with CeleryAdvanced task management with Celery
Advanced task management with CeleryMahendra M
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for AndroidTomáš Kypta
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroidSavvycom Savvycom
 
How To Use IO Monads in Scala?
 How To Use IO Monads in Scala? How To Use IO Monads in Scala?
How To Use IO Monads in Scala?Knoldus Inc.
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac pluginOleksandr Radchykov
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with geventMahendra M
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 

La actualidad más candente (20)

Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot Net
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
 
Understanding greenlet
Understanding greenletUnderstanding greenlet
Understanding greenlet
 
Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)
 
Introduction to Retrofit and RxJava
Introduction to Retrofit and RxJavaIntroduction to Retrofit and RxJava
Introduction to Retrofit and RxJava
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 
Fork/Join for Fun and Profit!
Fork/Join for Fun and Profit!Fork/Join for Fun and Profit!
Fork/Join for Fun and Profit!
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
 
Reactive Java (33rd Degree)
Reactive Java (33rd Degree)Reactive Java (33rd Degree)
Reactive Java (33rd Degree)
 
Fork and join framework
Fork and join frameworkFork and join framework
Fork and join framework
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
Advanced task management with Celery
Advanced task management with CeleryAdvanced task management with Celery
Advanced task management with Celery
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
How To Use IO Monads in Scala?
 How To Use IO Monads in Scala? How To Use IO Monads in Scala?
How To Use IO Monads in Scala?
 
Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac plugin
 
JVM
JVMJVM
JVM
 
Scaling Django with gevent
Scaling Django with geventScaling Django with gevent
Scaling Django with gevent
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 

Destacado

Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureJosé Paumard
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyHaim Yadid
 
mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingHaim Yadid
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice StackTomer Gabel
 
Java 8 Launch - MetaSpaces
Java 8 Launch - MetaSpacesJava 8 Launch - MetaSpaces
Java 8 Launch - MetaSpacesHaim Yadid
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinKai Koenig
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
使用 Java 上的 future/promise API
使用 Java 上的 future/promise  API使用 Java 上的 future/promise  API
使用 Java 上的 future/promise APIkoji lin
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaRick Warren
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8Garth Gilmour
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8AppDynamics
 
Reducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive StreamsReducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive Streamsjimriecken
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas Bonér
 

Destacado (17)

Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
 
mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profiling
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice Stack
 
Java 8 Launch - MetaSpaces
Java 8 Launch - MetaSpacesJava 8 Launch - MetaSpaces
Java 8 Launch - MetaSpaces
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with Kotlin
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
使用 Java 上的 future/promise API
使用 Java 上的 future/promise  API使用 Java 上的 future/promise  API
使用 Java 上的 future/promise API
 
ClassLoader Leaks
ClassLoader LeaksClassLoader Leaks
ClassLoader Leaks
 
The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
 
Resilience with Hystrix
Resilience with HystrixResilience with Hystrix
Resilience with Hystrix
 
Think Async in Java 8
Think Async in Java 8Think Async in Java 8
Think Async in Java 8
 
Reducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive StreamsReducing Microservice Complexity with Kafka and Reactive Streams
Reducing Microservice Complexity with Kafka and Reactive Streams
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 

Similar a The Future of Futures - A Talk About Java 8 CompletableFutures

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidEmanuele Di Saverio
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordKit Eason
 
how to reuse code
how to reuse codehow to reuse code
how to reuse codejleed1
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Artur Latoszewski
 
20170714 concurrency in julia
20170714 concurrency in julia20170714 concurrency in julia
20170714 concurrency in julia岳華 杜
 
Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8
Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8
Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8EPAM_Systems_Bulgaria
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka RemotingKnoldus Inc.
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and httpAlexe Bogdan
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundKarel Zikmund
 
Promises look into the async future
Promises look into the async futurePromises look into the async future
Promises look into the async futureslicejs
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrentRoger Xia
 
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...Víctor Bolinches
 
CSharp for Unity Day2
CSharp for Unity Day2CSharp for Unity Day2
CSharp for Unity Day2Duong Thanh
 
Martin Anderson - threads v actors
Martin Anderson - threads v actorsMartin Anderson - threads v actors
Martin Anderson - threads v actorsbloodredsun
 

Similar a The Future of Futures - A Talk About Java 8 CompletableFutures (20)

Programming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for AndroidProgramming Sideways: Asynchronous Techniques for Android
Programming Sideways: Asynchronous Techniques for Android
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, Hereford
 
Async java8
Async java8Async java8
Async java8
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
 
Intro to Pig UDF
Intro to Pig UDFIntro to Pig UDF
Intro to Pig UDF
 
20170714 concurrency in julia
20170714 concurrency in julia20170714 concurrency in julia
20170714 concurrency in julia
 
Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8
Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8
Tech Talks_04.07.15_Session 3_Martin Toshev_Concurrency Utilities In Java 8
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka Remoting
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
 
Promises look into the async future
Promises look into the async futurePromises look into the async future
Promises look into the async future
 
Java util concurrent
Java util concurrentJava util concurrent
Java util concurrent
 
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
Paradigma FP y OOP usando técnicas avanzadas de Programación | Programacion A...
 
CSharp for Unity Day2
CSharp for Unity Day2CSharp for Unity Day2
CSharp for Unity Day2
 
Martin Anderson - threads v actors
Martin Anderson - threads v actorsMartin Anderson - threads v actors
Martin Anderson - threads v actors
 

Más de Haim Yadid

Loom me up Scotty! Project Loom - What's in it for Me?
Loom me up Scotty!  Project Loom - What's in it for Me?Loom me up Scotty!  Project Loom - What's in it for Me?
Loom me up Scotty! Project Loom - What's in it for Me?Haim Yadid
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a FoeHaim Yadid
 
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the UglyKotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the UglyHaim Yadid
 
“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage CollectionHaim Yadid
 
Java Memory Structure
Java Memory Structure Java Memory Structure
Java Memory Structure Haim Yadid
 
Basic JVM Troubleshooting With Jmx
Basic JVM Troubleshooting With JmxBasic JVM Troubleshooting With Jmx
Basic JVM Troubleshooting With JmxHaim Yadid
 
The Freelancer Journey
The Freelancer JourneyThe Freelancer Journey
The Freelancer JourneyHaim Yadid
 
Building microservices with Kotlin
Building microservices with KotlinBuilding microservices with Kotlin
Building microservices with KotlinHaim Yadid
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...Haim Yadid
 
Java 8 - Stamped Lock
Java 8 - Stamped LockJava 8 - Stamped Lock
Java 8 - Stamped LockHaim Yadid
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Haim Yadid
 
A short Intro. to Java Mission Control
A short Intro. to Java Mission ControlA short Intro. to Java Mission Control
A short Intro. to Java Mission ControlHaim Yadid
 
Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions Haim Yadid
 
Tales About Scala Performance
Tales About Scala PerformanceTales About Scala Performance
Tales About Scala PerformanceHaim Yadid
 
Israeli JUG - IL JUG presentation
Israeli JUG -  IL JUG presentation Israeli JUG -  IL JUG presentation
Israeli JUG - IL JUG presentation Haim Yadid
 

Más de Haim Yadid (16)

Loom me up Scotty! Project Loom - What's in it for Me?
Loom me up Scotty!  Project Loom - What's in it for Me?Loom me up Scotty!  Project Loom - What's in it for Me?
Loom me up Scotty! Project Loom - What's in it for Me?
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
 
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the UglyKotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
 
“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection
 
Java Memory Structure
Java Memory Structure Java Memory Structure
Java Memory Structure
 
Basic JVM Troubleshooting With Jmx
Basic JVM Troubleshooting With JmxBasic JVM Troubleshooting With Jmx
Basic JVM Troubleshooting With Jmx
 
The Freelancer Journey
The Freelancer JourneyThe Freelancer Journey
The Freelancer Journey
 
Building microservices with Kotlin
Building microservices with KotlinBuilding microservices with Kotlin
Building microservices with Kotlin
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
 
Java 8 - Stamped Lock
Java 8 - Stamped LockJava 8 - Stamped Lock
Java 8 - Stamped Lock
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
A short Intro. to Java Mission Control
A short Intro. to Java Mission ControlA short Intro. to Java Mission Control
A short Intro. to Java Mission Control
 
Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions
 
Tales About Scala Performance
Tales About Scala PerformanceTales About Scala Performance
Tales About Scala Performance
 
Israeli JUG - IL JUG presentation
Israeli JUG -  IL JUG presentation Israeli JUG -  IL JUG presentation
Israeli JUG - IL JUG presentation
 

Último

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Último (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

The Future of Futures - A Talk About Java 8 CompletableFutures

  • 1. ilJUG  Java  8  Launch  Event     The  Future  of  Futures   (Apr  2014)   ! Haim Yadid - Performize-IT
  • 2. About  Me:  Haim  Yadid •21 Years of SW development experience •Performance Expert •Consulting R&D Groups •Training: Java Performance Optimization •Organizing : ILJUG
  • 3. IL  JUG •Israeli Java User Group •Reborn at 1/14 •Meetup : http://www.meetup.com/IL-JUG •G+: https://plus.google.com/u/0/communities/110138558454900054301 •Twitter: @il_jug
  • 4.
  • 5. The  Beginning  of  Times •Before J1.5 •Primitive life forms without Future •Threads •synchronization primitives •wait / notify •Most likely you will do it wrong
  • 6. Futures  Introduction •j.u.c.Future •introduced in JDK 1.5 •jsr166 (Doug Lea) •Together with Executors •And many other concurrency constructs •Part of the java.util.concurrent
  • 7. What  is  a  Future •A container for a result that will become available at a later time •Backed by a thread •May contain a Throwable if computation fails
  • 8. What  is  a  Future •Future means asynchronous •Future does not mean non blocking •Future does not mean reactive
  • 9. The  ExecutorService •Executor service is the container which handles a future •Has the threads which futures need. •Part of j.u.c (Executors.newXXX) •SingleThreadExecutor •FixedThreadPool •CachedThreadPool •ScheduledThreadPool
  • 10. Simplest  Example ExecutorService e = Executors.newSingleThreadExecutor();
 ! Future<Integer> future = e.submit(
 () -> {sleep(1000);return 42;}
 ) ; // do something useful ? System.out.println(future.get()); Lambda  expression  which   represents  a   Callable<Integer> User Task(Callable,   Runnable) Future Executor
  • 11. What  Else  Can  Be  Done? •So we are blocked until future is finished •If it throw exception get will throw an exception •More that can be done: ! ! ! •And thats all ! future.cancel(false) ; // cancel future if not executed yet (in queue) 
 future.cancel(true); // in addition interrupt the running task
 future.isCancelled(); // wether the future is cancelled.
 future.idDone() // whether the future is done.
  • 12. Futures  Pros •Futures combined with Callables are cheaper than threads. •Easier to maintain. •Async We  will  get  to  the  cons…
  • 13. Futures  Evolution  -­‐  Java  6 •Java 6 -jsr166x (CompletionService) •Separation of concerns ExecutorService e = Executors.newFixedThreadPool(10);
 ! CompletionService<Integer> completionService = new ExecutorCompletionService<>(e);
 ! completionService.submit(() -> {sleep(1000); return 42;}) ;
 ! Future<Integer> future = completionService.take();
 System.out.println(future.get()); // already completed….. User Future Executor Consumer Task
  • 14. Futures  Evolution  -­‐  Java  7 •Java7 - jsr166y (Fork Join Pools) •Has a common pool •ForkJoinTask extends Future •Completion ? ForkJoinTask<Integer> task = ForkJoinPool.commonPool(). submit( () -> {
 sleep(1000);
 System.out.printf("done");
 }); System.out.println(task.get());
  • 15. complete()    a  Complete  mess •With the method complete you can introduce a value before task competes. •But ForkJoinTask<Integer> task = ForkJoinPool.commonPool().
 submit(() -> {
 sleep(1000);
 return 42;
 });
 ! sleep(10); task.complete(43);
 System.out.println(task.get()); task.complete(44);
 System.out.println(task.get()); sleep(2000);
 System.out.println(task.get()); 43   42   44  
  • 16.
  • 17. Nothing •Dinosaurs are perfect •They are big •Powerful •State of the art Nothing,  but  evolution  
  • 18. Alternatives •Akka Futures/Scala Futures •Scala Promises •Twitter - Finnagle •Guava ListenableFuture •Groovy Dataflow concurrency (GPars)
  • 19. Proper  Completion •A correct way to complete a future. •Once a future is completed it immutable •It is IMPORTANT
  • 20. Data-­‐flow  Concurrency •If we have variables that can be written to once •We have deterministic behaviour! •Run it a million times it will still work the same!!!
  • 21. Composition •Looking for websites that will interest a group of people Get  Profile   On  linked  in   user  1 Find  intersection  of  skills Get  Profile   On  linked  in   user  1 Get  Profile   On  linked  in   user  n search  on   google Send  mail  with  group  recommendation …….
  • 22.
  • 23.  CompletableFuture  Is •A container for a result that will become available at a later time •Backed by thread •May contain a Throwable if computation failed
  • 24. CompletableFuture  Is •Means asynchronous •Does not mean non blocking •Does not mean reactive
  • 25. Is  Completable •Is completed when completed! •The result can be set once. •Either by the task itself •Or from outside.
  • 26. Is  Composable •Composable •Lambda expression friendly •More functional in it’s nature
  • 27. CompletableFuture  Creation •supplyAsync •runAsync import  java.util.concurrent.CompletableFuture;
 import  static  java.util.concurrent.CompletableFuture.*;              CompletableFuture<Integer>  f  =  supplyAsync(                                  ()  -­‐>  {sleep(10000);return  42;}
                );                  f.join(); Runs  on  ForkJoinPool.commonPool;   You  can  supply  an  executor  if  you  wantjoin  is  the  same  as  get  but  throws  an   unchecked  exception  (hip  hip  hurray)
  • 28. Construction •new CompletableFuture(); •use complete(r) to complete it •use completeExceptionally(t) to complete with an exception  CompletableFuture<Integer>  a=  new  CompletableFuture<>();  a.complete(5);
 
  a.completeExceptionally(new  IndexOutOfBoundsException());  
  • 29. CompletableFuture •Implements CompletableStage •A large set of methods (~60 •Every method is multiplied by three •XXXX(….) •XXXXAsync(…) •XXXX(….,Executor x)
  • 30. Future  -­‐>  CompletableFuture •Not really possible (Cleanly)                Future<Integer>  future  =  ForkJoinPool.commonPool().submit(
   ()  -­‐>  {sleep(4000);return  42;}
                );
 !                CompletableFuture<Integer>  brighterFuture  =  supplyAsync(()  -­‐>  {
                        try  {
                                return  future.get();
                        }  catch  (Exception  e1)  {
                                throw  new  RuntimeException(e1);
                        }
                });
 
                System.out.println(brighterFuture.get()); Nasty  Exception   handling   Requires   another   thread….
  • 31. !
  • 32. thenApply •Apply another action when result is available             CompletableFuture<Integer>  f  =  supplyAsync(
                        ()  -­‐>  {sleep(10000);return  42;});
 ! CompletableFuture<Integer>  f2  =    f.thenApply((r)  -­‐>  r*r); CompletableFuture<Integer>  f2  =    f.thenApplyAsync((r)  -­‐>  r*r); CompletableFuture<Integer>  f2  =    f.thenApplyAsync((r)  -­‐>  r*r,
                                                myLowPriorityExecutor);
  • 33. Handling  Exceptions •exceptionally() CompletableFuture<Integer>  f  =  supplyAsync(
                                ()  -­‐>  {sleep(10000);
                                if  (true)  throw  new  RuntimeException();  
                                return  42;});
 ! CompletableFuture<Integer>  f2  =  
                        f.exceptionally((t)-­‐>  2).
                            thenApply((r)  -­‐>  r*r);
 
 System.out.println(f2.get());
  • 34. The  General  Case •handle() - gets result and throwable manipulates them •whenComplete() - does something, pass result through CompletableFuture<Integer>  f2  =  f.handle(
                      (res,throwable)  -­‐>  (throwable==null)?  res*res  :  2);  
 ! CompletableFuture<Integer>  f3  =  f.whenComplete(
                              (res,  throwable)  -­‐>  {System.out.println("done");});
  • 35. Composition •thenCompose() •Performs another stage upon completion •On failure stage will not be performed                CompletableFuture<Integer>  f1  =  supplyAsync(
                                ()  -­‐>  {sleep(2100);return  42;});
 !                CompletableFuture<Integer>  f2  =  f1.thenCompose(
                                (v)  -­‐>  supplyAsync(()  -­‐>  {sleep(2100);return  v+42;}))    ;
 
                System.out.println(f2.get());
  • 36. Combiners •thenCombine() take both results and apply a function on them •thenAcceptBoth() - guess                CompletableFuture<Integer>  f1  =  supplyAsync(
                                ()  -­‐>  {sleep(2100);return  42;});
                CompletableFuture<Integer>  f2  =  supplyAsync(
                                ()  -­‐>  {sleep(2100);return  55;});
 !                CompletableFuture<Integer>  f3  =  f1.thenCombine(f2,
                                (r1,r2)  -­‐>  r1+r2)    ;                  CompletableFuture<Void>  f4  =  f1.thenAcceptBoth(f2,
                                (r1,  r2)  -­‐>  System.out.println(r1  +  r2))    ;
                System.out.println(f3.get());
  • 37. Either… •thenApplyEither() take fastest result use it. Discard the second one •If exception is thrown behaviour is not predictable •Use case: parse fastest server result                CompletableFuture<Integer>  f1  =  supplyAsync(
                                ()  -­‐>  {sleep(2300);return  42;});
                CompletableFuture<Integer>  f2  =  supplyAsync(
                                ()  -­‐>  {sleep(2200);return  43;});
 !                CompletableFuture<Integer>  f3  =  f1.applyToEither(f2,(r)  -­‐>  r  *  r);
  • 38. A  Better  Either •Hold down exceptions letting other futures a chance to complete  static<T>  CompletableFuture<T>
  holdDownExceptionally(CompletableFuture<T>f,  CountDownLatch  latch)  {                  return  f.exceptionally((t)  -­‐>  {
                                try  {
                                        latch.countDown();latch.await();
                                }  catch  (Exception  e)  {
                                        throw  new  RuntimeException(t);
                                }
                                throw  new  RuntimeException(t);
                          }).                            thenApply((r)  -­‐>  {latch.countDown();latch.countDown();return  r;});
        }
  • 39. A  Better  Either  cont static  <T,U>  CompletableFuture<U>
 myApplytoEither(CompletableFuture<T>  f1,  
                                                              CompletableFuture<T>  f2,
                                                              Function<?  super  T,  U>  fn)  
  {                  CountDownLatch  latch  =  new  CountDownLatch(2);                  CompletableFuture<T>  f1be  =  holdDownExceptionally(f1,latch);
                CompletableFuture<T>  f2be  =  holdDownExceptionally(f2,latch);                  return  f1be.applyToEither(f2be,fn);
 }
  • 40. How  Many? •A completable future may have more than one dependents •Use getNumberOfDependents to get an estimate CompletableFuture<Integer>  f  =  supplyAsync(
                        ()  -­‐>  {sleep(10000);return  42;});
 ! CompletableFuture<Integer>  f2  =    f.thenApply((r)  -­‐>  r*r);
 CompletableFuture<Integer>  f3  =    f.thenApply((r)  -­‐>  r*r*r);
 CompletableFuture<Integer>  f4  =    f.thenApply((r)  -­‐>  r*r*r*r);
 ! f.getNumberOfDependents();      //  returns  3
  • 41. Helper  Static  Functions •allOf(CompletableFuture<?>... cfs) •no value returned •anyOf(CompletableFuture<?>... cfs) •object retured
  • 42. NIO  Non  blocking  IO •Selectors •dispatchers •Reactor pattern •There is no support out of the box for CompletableFutures in NIO
  • 43. What  about  J7  NIO2 •AsynchronousFileChannel •AsynchronousServerSocketChannel •Are using futures •Not adapted for completable futures. AsynchronousFileChannel  afc  =      
            AsynchronousFileChannel.open(Paths.get(“Video.avi"),        
                        StandardOpenOption.READ)      ;   
 ByteBuffer  r  =  ByteBuffer.allocate(500*1024*1024)  ;
  Future<Integer>  a  =  afc.read(r,10*1024*1024);       //do  something  useful  while  waiting     a.get();      
  • 44. Further  Info •All examples can be found in github •https://github.com/lifey/compfut.git •Concurrency Interest Mailing List •Java Concurrency in Practice(Brian Goatz) •http://www.slideshare.net/kojilin/ completable-future
  • 45.
  • 46. Thanks + Q&A + Contact Me © Copyright Performize-IT LTD. http://il.linkedin.com/in/haimyadid lifey@performize-it.com www.performize-it.com blog.performize-it.com https://github.com/lifey @lifeyx