Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Of concurrency and other demons

Of concurrency and other demons

Talk about concurrency.
Initially presented at DawsCon with Hillmer Chona

1d2a6c7cfa9e96ecffe3c10a5018b1b8?s=128

Rodrigo Graciano

January 16, 2021
Tweet

Transcript

  1. None
  2. ➔ Software developer - Team lead ➔ Java Champion ➔

    Medellin Java Users Group Leader ➔ hibernate/hibernate-validator Contributor ➔ Duke’s Choice Award Winner ➔ Eclipse Collections contributor
  3. ➔ Professional with 10+ years ➔ Principal Software Engineer -

    NY ➔ NYJavaSIG Leader ➔ graciano.dev ➔ Twitter: @rodrigograciano
  4. • • • •

  5. • Concurrency when we have many task, largely independent, and

    we use the same resource to do them at a time • Parallelism is when we want to do one task, and we split up in multiple subtasks
  6. A Thread is an independent path of execution that allows

    a program to operate more efficiently by doing multiple things at the same time. Threads can be used to perform complicated tasks in the background without interrupting the main program.
  7. • Synchronous: when we wait to finish a task before

    moving to the next one • Asynchronous: when we move to another task before it finishes
  8. • Thread t = new Thread( ()-> this.doSomething( thing ));

    t.start(); • ExecutorService executor = Executors.newFixedThreadPool( 10 ); Future<?> future = executor.submit( ()-> this.doSomething( thing )); • CompletableFuture.runAsync( ()-> this.doSomething( thing )); • Thread.builder().virtual().name("name").task(() -> this.doSomething( thing )).start();
  9. None
  10. None
  11. Stream API CompletableFuture Creation Chained operations Return forEach runAsync thenAccept

    / thenRun void map supplyAsync thenApply CompletableFuture<U>
  12. None
  13. CompletableFuture<Void>::runAsync (Runnable runnable) <U> CompletableFuture<U>::supplyAsync (Supplier<U> supplier) CompletableFuture<Void>::runAsync (Runnable runnable,

    Executor executor) <U> CompletableFuture<U>::supplyAsync (Supplier<U> supplier, Executor executor)
  14. static ExecutorService newCachedThreadPool() static ExecutorService newFixedThreadPool (int nThreads) static ScheduledExecutorService

    newScheduledThreadPool (int corePoolSize) static ExecutorService newSingleThreadExecutor() static ScheduledExecutorService newSingleThreadScheduledExecutor() static ExecutorService newWorkStealingPool()
  15. T::get () throws InterruptedException , ExecutionException T::get (long timeout, TimeUnit

    unit) throws InterruptedException , ExecutionException , TimeoutException T::getNow (T valueIfAbsent) T::join()
  16. • • • •