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

Rodrigo Graciano

January 16, 2021
Tweet

More Decks by Rodrigo Graciano

Other Decks in Technology

Transcript

  1. View Slide

  2. ➔ Software developer - Team lead
    ➔ Java Champion
    ➔ Medellin Java Users Group Leader
    ➔ hibernate/hibernate-validator Contributor
    ➔ Duke’s Choice Award Winner
    ➔ Eclipse Collections contributor

    View Slide

  3. ➔ Professional with 10+ years
    ➔ Principal Software Engineer - NY
    ➔ NYJavaSIG Leader
    ➔ graciano.dev
    ➔ Twitter: @rodrigograciano

    View Slide





  4. View Slide

  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

    View Slide

  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.

    View Slide

  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

    View Slide


  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();

    View Slide

  9. View Slide

  10. View Slide

  11. Stream API CompletableFuture
    Creation Chained operations Return
    forEach runAsync thenAccept / thenRun void
    map supplyAsync thenApply CompletableFuture

    View Slide

  12. View Slide

  13. CompletableFuture::runAsync (Runnable runnable)
    CompletableFuture::supplyAsync (Supplier supplier)
    CompletableFuture::runAsync (Runnable runnable, Executor executor)
    CompletableFuture::supplyAsync (Supplier supplier, Executor executor)

    View Slide

  14. static ExecutorService newCachedThreadPool()
    static ExecutorService newFixedThreadPool (int nThreads)
    static ScheduledExecutorService newScheduledThreadPool (int corePoolSize)
    static ExecutorService newSingleThreadExecutor()
    static ScheduledExecutorService newSingleThreadScheduledExecutor()
    static ExecutorService newWorkStealingPool()

    View Slide

  15. T::get () throws InterruptedException , ExecutionException
    T::get (long timeout, TimeUnit unit) throws InterruptedException ,
    ExecutionException , TimeoutException
    T::getNow (T valueIfAbsent)
    T::join()

    View Slide





  16. View Slide