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

Write You An Actor (System) For Great Good!

Write You An Actor (System) For Great Good!

Edoardo Vacchi

March 27, 2023
Tweet

More Decks by Edoardo Vacchi

Other Decks in Programming

Transcript

  1. Write You an
    Actor (System) for
    Great Good!
    (with JBang, JDK 19, records, pattern
    matching and virtual threads!)

    View Slide

  2. Andrea
    Peruffo
    @and_prf
    Edoardo
    Vacchi
    @evacchi

    View Slide

  3. View Slide

  4. This Is Not A Talk
    About Actor
    Systems

    View Slide

  5. This Is Not A Talk
    About Actor
    Systems

    View Slide

  6. This Is Not Only A Talk
    About Actor
    Systems

    View Slide

  7. evacchi.github.io

    View Slide

  8. @evacchi
    About Me
    Edoardo Vacchi @evacchi
    ● PL/DSL Research @ UniMi
    ● R&D @ UniCredit Bank
    ● Drools, Kogito @ Red Hat

    View Slide

  9. gist.github.com/viktorklang/2362563

    View Slide

  10. gist.github.com/viktorklang/2362563

    View Slide

  11. Has Java reached
    feature parity with
    10-years ago Scala?

    View Slide

  12. Has Java reached
    feature parity with
    10-years ago Scala?

    View Slide

  13. Has Java reached
    feature parity with
    10-years ago Scala?

    View Slide

  14. Has Java reached
    feature parity with
    10-years ago Scala?

    View Slide

  15. package io.github.evacchi;
    import java.util.concurrent.*;
    import java.util.concurrent.atomic.AtomicInteger;
    import java.util.function.Function;
    import static java.lang.System.out;
    public interface Actor {
    interface Behavior extends Function {}
    interface Effect extends Function {}
    interface Address { Address tell(Object msg); }
    static Effect Become(Behavior like) { return old -> like; }
    static Effect Stay = old -> old;
    static Effect Die = Become(msg -> { out.println("Dropping msg [" + msg + "] due to severe case of death."); return Stay; });
    record System(ExecutorService executorService) {
    public Address actorOf(Function initial) {
    abstract class AtomicRunnableAddress implements Address, Runnable
    { final AtomicInteger on = new AtomicInteger(0); }
    var addr = new AtomicRunnableAddress() {
    final ConcurrentLinkedQueue mb = new ConcurrentLinkedQueue<>();
    Behavior behavior = m -> (m instanceof Address self) ? Become(initial.apply(self)) : Stay;
    public Address tell(Object msg) { mb.offer(msg); async(); return this; }
    public void run() {
    try { if (on.get() == 1) { var m = mb.poll(); if (m!=null) { behavior = behavior.apply(m).apply(behavior); } }}
    finally { on.set(0); async(); }}
    void async() {
    if (!mb.isEmpty() && on.compareAndSet(0, 1)) {
    try { executorService.execute(this); }
    catch (Throwable t) { on.set(0); throw t; }}}
    };
    return addr.tell(addr);
    }
    }
    }
    evacchi.github.io

    View Slide

  16. @evacchi
    What You Will Bring Home
    ● Learn new Java 19 features
    ● Learn an interesting concurrency model
    ● Learn how to run code snippets with JBang

    View Slide

  17. @evacchi
    What You Will Bring Home
    ● Learn new Java 19 features
    ● Learn an interesting concurrency model
    ● Learn how to run code snippets with JBang
    ● Learn how to write concise Java program
    with tricks that will make your coworkers mad

    View Slide

  18. Agenda

    View Slide

  19. @evacchi
    Agenda
    ● What is an actor?
    ● Comparison between actor runtimes
    ● Features of Java we will be using

    ● Examples of actors (live coding)
    ● An actor runtime (live coding)
    ● A typed actor runtime (live coding)

    ● An actor-based chat (live coding)
    ● Virtual Threads and Project Loom
    ● A Loom-based chat (live coding)
    Live coding with

    View Slide

  20. Actor Definition

    View Slide

  21. @evacchi
    Actor Definition
    An actor is a computational entity that, in response to a message it
    receives, can concurrently:
    ● send a finite number of messages to other actors;
    ● create a finite number of new actors;
    ● designate the behavior to be used for the next message it receives.
    "Everything" is an actor.

    View Slide

  22. @evacchi
    Actor Model
    ● Modelling stateful systems
    ● Distributed systems (e.g. leveraging location transparency)
    ● IoT (e.g. Digital twins)

    View Slide

  23. @evacchi
    Actor Model
    ● Concurrency Model
    ● Simple
    ● "Single-Thread" reasoning
    ● Message-based, "Mailbox"

    View Slide

  24. @evacchi
    Implementation
    Function + State + Message Queue

    View Slide

  25. @evacchi
    Implementation
    Function + State + Message Queue

    View Slide

  26. @evacchi
    Implementation
    Function + State + Message Queue

    View Slide

  27. @evacchi
    🖂 ➡ 🖂 🖂 🖂 🖂 🖂 🖂
    Implementation
    Private State
    Behavior
    mailbox

    View Slide

  28. @evacchi
    Implementation
    🖂 🖂 🖂 🖂 🖂 🖂 🖂
    Private State
    Behavior

    View Slide

  29. @evacchi
    Implementation
    🖂 🖂 🖂 🖂 🖂 🖂
    Private State
    Behavior
    🖂

    View Slide

  30. @evacchi
    Implementation
    🖂 🖂 🖂 🖂 🖂 🖂
    Private State
    Behavior
    🖂

    View Slide

  31. @evacchi
    Implementation
    🖂 🖂 🖂 🖂 🖂 🖂
    Private State
    Behavior
    🖂
    📤

    View Slide

  32. @evacchi
    Implementation
    🖂 🖂 🖂 🖂 🖂 🖂
    Private State
    Behavior
    🖂 🖂 ➡

    View Slide

  33. @evacchi
    Messages vs Methods
    ● you send a message to an actor
    ● you invoke a method on an object
    ● however in Smalltalk you send "messages"
    to objects

    View Slide

  34. @evacchi
    Messages vs Methods
    ● you send a message to an actor
    ● you invoke a method on an object
    ● however in Smalltalk you send "messages"
    to objects
    ● in fact, some people think that actors
    are "proper" OOP as envisioned by
    Alan Kay

    View Slide

  35. https://twitter.com/joeerl/status/1107348549132533760
    @evacchi

    View Slide

  36. https://twitter.com/joeerl/status/1107544833911128064
    @evacchi

    View Slide

  37. https://twitter.com/joeerl/status/1107544833911128064

    View Slide

  38. @evacchi
    Spawning Actors

    View Slide

  39. @evacchi
    Vending Machines (FSM)

    View Slide

  40. Actor Runtimes

    View Slide

  41. @evacchi
    When Scala Roamed The World
    ● Java 8 in 2014
    ● Context: JDK 5/6/7
    ○ Mainstream statically typed OOP programming languages
    were verbose (C++/Java/C#)
    ○ Dynamic languages were more concise (Python/Ruby/Groovy)
    ● Enter Scala
    ○ Static typing
    ○ Dynamic feel / conciseness
    ○ Actor library

    View Slide

  42. @evacchi
    When Scala Roamed The World
    ● Context: JDK 5/6/7
    ○ Mainstream statically typed OOP programming languages
    were verbose (C++/Java/C#)
    ○ Dynamic languages were more concise Python/Ruby/Groovy
    ● Enter Scala
    ○ Static typing
    ○ Dynamic feel / conciseness
    ○ Actor library

    View Slide

  43. @evacchi
    Akka (Scala)
    case object Ping
    class Pingponger extends Actor {
    var count = 10
    def receive: Any => Unit = {
    case Ping =>
    println(s"${self.path} received ping, count down $count")
    if (this.count > 0) {
    this.count = this.count - 1
    sender() ! Ping
    }
    }
    }
    val system = ActorSystem("pingpong")
    val pinger = system.actorOf(Props[Pingponger](), "pinger")
    val ponger = system.actorOf(Props[Pingponger](), "ponger")
    pinger.tell(Ping, ponger)

    View Slide

  44. @evacchi
    Akka (Scala)
    case class Ping(count: Int)
    class Pingponger extends Actor {
    def receive: Any => Unit = {
    case Ping(count) =>
    println(s"${self.path} received ping, count down $count")
    if (count > 0) {
    sender() ! Ping(count - 1)
    }
    }
    }
    val system = ActorSystem("pingpong")
    val pinger = system.actorOf(Props[Pingponger](), "pinger")
    val ponger = system.actorOf(Props[Pingponger](), "ponger")
    pinger.tell(Ping(10), ponger)

    View Slide

  45. @evacchi
    Akka (Scala)
    case class Ping(count: Int)
    class Pingponger extends Actor {
    def receive(msg: Any): Unit =
    msg match {
    case Ping(count) =>
    println(s"${self.path} received ping, count down $count")
    if (count > 0) {
    sender() ! Ping(count - 1)
    }
    }
    }
    val system = ActorSystem("pingpong")
    val pinger = system.actorOf(Props[Pingponger](), "pinger")
    val ponger = system.actorOf(Props[Pingponger](), "ponger")
    pinger.tell(Ping(10), ponger)

    View Slide

  46. @evacchi
    Akka + Java
    public class MyUntypedActor extends UntypedActor {
    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
    public void onReceive(Object message) throws Exception {
    if (message instanceof Ping) {
    Ping p = (Ping) message;
    if (p.count() > 0) {
    log.info("Received ping : " + p.count());
    getSender().tell(new Ping(p.count() - 1), getSelf());
    }
    }
    }

    View Slide

  47. @evacchi
    Scala
    Groovy
    Ruby
    Python
    Java

    View Slide

  48. @evacchi
    Erlang
    pingponger(Name, Main) ->
    receive
    {ping, Count, Ping_PID} ->
    io:format("~s received ping, count down ~w~n", [Name, Count]),
    if Count > 0 ->
    Ping_PID ! {ping, Count - 1, self()},
    pingponger(Name, Main);
    true ->
    exit ("done")
    end
    end.
    main(_) ->
    Ping1_PID = spawn(fun() -> pingponger("pinger", self()) end),
    Ping2_PID = spawn(fun() -> pingponger("ponger", self()) end),
    Ping1_PID ! {ping, 10, Ping2_PID}.

    View Slide

  49. @evacchi
    Elixir
    defmodule Main do
    def pingponger(name) do
    receive do
    {:ping, count, sender} ->
    IO.puts "#{name} received ping, count down #{count}"
    if count > 0 do
    send sender, {:ping, count - 1, self()}
    pingponger(name)
    else
    :ok
    end
    end
    end
    end
    pid1 = spawn fn -> Main.pingponger("pinger") end
    pid2 = spawn fn -> Main.pingponger("ponger") end
    send pid1, {:ping, 10, pid2}

    View Slide

  50. @evacchi
    Scala
    Groovy
    Ruby
    Python
    Java
    Erlang
    Elixir

    View Slide

  51. @evacchi
    Akka + Java
    public class MyUntypedActor extends UntypedActor {
    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
    public void onReceive(Object message) throws Exception {
    if (message instanceof Ping) {
    Ping p = (Ping) message;
    if (p.count() > 0) {
    log.info("Received ping : " + p.count());
    getSender().tell(new Ping(p.count() - 1), getSelf());
    }
    }
    } Can we improve over this?

    View Slide

  52. Tools Of The Trade

    View Slide

  53. @evacchi
    (Ab)using Language Defaults To Reduce Noise
    public class Main {
    public static final String HELLO = "hello world";
    public static void main(String[] args) {
    System.out.println(HELLO);
    }
    }

    View Slide

  54. @evacchi
    (Ab)using Language Defaults To Reduce Noise
    public class Main {
    public static final String HELLO = "hello world";
    public static void main(String[] args) {
    System.out.println(HELLO);
    }
    }

    View Slide

  55. @evacchi
    (Ab)using Language Defaults To Reduce Noise
    public interface Main {
    public static final String HELLO = "hello world";
    public static void main(String[] args) {
    System.out.println(HELLO);
    }
    }

    View Slide

  56. @evacchi
    (Ab)using Language Defaults To Reduce Noise
    public interface Main {
    public static final String HELLO = "hello world";
    public static void main(String[] args) {
    System.out.println(HELLO);
    }
    }

    View Slide

  57. @evacchi
    (Ab)using Language Defaults To Reduce Noise
    import static java.lang.System.*;
    public interface Main {
    public static final String HELLO = "hello world";
    public static void main(String[] args) {
    System.out.println(HELLO);
    }
    }

    View Slide

  58. @evacchi
    (Ab)using Language Defaults To Reduce Noise
    import static java.lang.System.*;
    interface Main {
    String HELLO = "hello world";
    static void main(String... args) { out.println(HELLO); }
    }

    View Slide

  59. https://openjdk.org/projects/amber/design-notes/on-ramp

    View Slide

  60. public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }
    @evacchi

    View Slide

  61. public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }
    @evacchi

    View Slide

  62. public class HelloWorld {
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }
    void main() {
    println("Hello World");
    }
    @evacchi

    View Slide

  63. Is This
    Code-Golfing?
    me
    recent Java
    syntax

    View Slide

  64. @evacchi
    More “Code Golfing”
    public class Auth {
    private final String login;
    private final String token;
    public Auth(String login, String token) {
    this.login = login;
    this.token = token;
    }
    public String login() { return this.login; }
    public String token() { return this.token; }
    public boolean equals(Object o) { ... }
    public int hashCode() { return Objects.hash(login, token); }
    public String toString() { ... }
    }
    public class Anon {
    private final String email;
    public Anon(String email) { this.email = email; }
    public String email() { return this.email; }
    public boolean equals(Object o) { ... }
    public int hashCode() { ... }
    public String toString() { ... }
    }

    View Slide

  65. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    if (message instanceof Auth) {
    Auth a = (Auth) message;
    check(a.login());
    if (validate(a.login(), a.token())) {
    // grant full access
    } else {
    // error
    }
    } else if (message instanceof Anon) {
    Anon a = (Anon) message;
    // grant guest access
    } else
    unhandled(message);
    }

    View Slide

  66. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    if (message instanceof Auth) {
    Auth a = (Auth) message;
    check(a.login());
    if (validate(a.login(), a.token())) {
    // grant full access
    } else {
    // error
    }
    } else if (message instanceof Anon) {
    Anon a = (Anon) message;
    // grant guest access
    } else
    unhandled(message);
    }

    View Slide

  67. @evacchi
    Enhanced instanceof
    public void onReceive(Object message) throws Exception {
    if (message instanceof Auth a) {
    check(a.login());
    if (validate(a.login(), a.token())) {
    // grant full access
    } else {
    // error
    }
    } else if (message instanceof Anon a) {
    // grant guest access
    } else
    unhandled(message);
    }
    pattern matching

    View Slide

  68. @evacchi
    More “Code Golfing”
    public class Auth {
    private final String login;
    private final String token;
    public Auth(String login, String token) {
    this.login = login;
    this.token = token;
    }
    public String login() { return this.login; }
    public String token() { return this.token; }
    public boolean equals(Object o) { ... }
    public int hashCode() { return Objects.hash(login, token); }
    public String toString() { ... }
    }
    public class Anon {
    private final String email;
    public Anon(String email) { this.email = email; }
    public String email() { return this.email; }
    public boolean equals(Object o) { ... }
    public int hashCode() { ... }
    public String toString() { ... }
    }

    View Slide

  69. @evacchi
    Records
    public record Auth(String login, String token) {}
    public record Anon(String email) {}

    View Slide

  70. @evacchi
    Enhanced instanceof
    public void onReceive(Object message) throws Exception {
    if (message instanceof Auth(var login, var token)) {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    } else if (message instanceof Anon(String email)) {
    // grant guest access
    } else
    unhandled(message);
    }
    deconstruction patterns

    View Slide

  71. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    default -> unhandled(message);
    }
    }

    View Slide

  72. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    default -> unhandled(message);
    }
    }
    Improved Switch

    View Slide

  73. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    default -> unhandled(message);
    }
    }
    Records

    View Slide

  74. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    default -> unhandled(message);
    }
    }
    deconstruction patterns

    View Slide

  75. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    default -> unhandled(message);
    }
    }
    var
    pattern

    View Slide

  76. @evacchi
    More “Code Golfing”
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    default -> unhandled(message);
    }
    }

    View Slide

  77. @evacchi
    Records
    public record Auth(String login, String token) {}
    public record Anon(String email) {}

    View Slide

  78. @evacchi
    Sealed Hierarchies
    sealed interface LoginInfo {}
    public record Auth(String login, String token) implements LoginInfo {}
    public record Anon(String email) implements LoginInfo {}

    View Slide

  79. @evacchi
    Exhaustive Pattern Matching
    public void onReceive(LoginInfo message) throws Exception {
    switch (message) {
    case Auth(var login, var token) -> {
    check(login);
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(var email) -> { /* guest access */ };
    }
    }
    Sealed Type Hierarchy
    No Default Case!

    View Slide

  80. @evacchi
    Scala
    def onReceive(Any: message): Unit {
    message match {
    case Auth(login, token) => {
    check(login)
    if (validate(login, token)) {
    // grant full access
    } else {
    // error
    }
    }
    case Anon(email) => { /* guest access */ };
    }
    }

    View Slide

  81. @evacchi
    Akka + Java + Pattern Matching
    public class MyUntypedActor extends UntypedActor {
    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
    public void onReceive(Object message) throws Exception {
    switch (message) {
    case String m -> {
    log.info("Received String message: {}", message);
    getSender().tell(message, getSelf());
    }
    default -> unhandled(message);
    }
    }
    }

    View Slide

  82. @evacchi
    Akka + Java
    static class Pingponger extends AbstractActor {
    @Override
    public Receive createReceive() {
    return receiveBuilder()
    .match(
    Ping.class,
    ping -> {
    out.println(getSelf().path() + " received ping, count down " + ping.getCount());
    if (ping.getCount() > 0) {
    getSender().tell(new Ping(ping.getCount() - 1), getSelf());
    }
    })
    .build();
    }
    }
    public static void main(String... args) {
    ActorSystem system = ActorSystem.apply("pingpong");
    ActorRef pinger = system.actorOf(Props.create(Pingponger.class), "pinger");
    ActorRef ponger = system.actorOf(Props.create(Pingponger.class), "ponger");
    pinger.tell(new Ping(10), ponger);
    }

    View Slide

  83. gist.github.com/viktorklang/2557678

    View Slide

  84. @evacchi
    Agenda
    ● What is an actor?
    ● Comparison between actor runtimes
    ● Features of Java we will be using

    ● Examples of actors (live coding)
    ● An actor runtime (live coding)
    ● A typed actor runtime (live coding)

    ● An actor-based chat (live coding)
    ● Virtual Threads and Project Loom
    ● A Loom-based chat (live coding)
    Live coding with

    View Slide

  85. Live Coding with

    View Slide

  86. @evacchi
    My First Actor

    View Slide

  87. @evacchi
    Vending Machines (FSM)

    View Slide

  88. Closures vs Classes

    View Slide

  89. @evacchi
    Implementation
    Function + State + Message Queue

    View Slide

  90. @evacchi
    Closures vs Classes
    The venerable master Qc Na was walking with his student, Anton.
    Hoping to prompt the master into a discussion, Anton said
    “Master, I have heard that objects are a very good thing - is this true?”
    Qc Na looked pityingly at his student and replied…

    View Slide

  91. @evacchi
    Closures vs Classes
    “Foolish pupil – objects are merely a poor man’s closures.”

    View Slide

  92. @evacchi
    Closures vs Classes
    Chastised, Anton took his leave from his master and returned to his cell,
    intent on studying closures. He carefully read the entire "Lambda: The
    Ultimate..." series of papers and its cousins, and implemented a small
    Scheme interpreter with a closure-based object system. He learned much, and
    looked forward to informing his master of his progress.

    View Slide

  93. @evacchi
    Closures vs Classes
    On his next walk with Qc Na, Anton attempted to impress his master by
    saying “Master, I have diligently studied the matter, and now understand
    that objects are truly a poor man’s closures.” Qc Na responded by hitting
    Anton with his stick, saying…

    View Slide

  94. @evacchi
    Closures vs Classes
    “When will you learn? Closures are a poor man's object.”

    View Slide

  95. @evacchi
    Closures vs Classes
    At that moment, Anton became enlightened.
    http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html

    View Slide

  96. @evacchi
    Agenda
    ● What is an actor?
    ● Comparison between actor runtimes
    ● Features of Java we will be using

    ● Examples of actors (live coding)
    ● An actor runtime (live coding)
    ● A typed actor runtime (live coding)

    ● An actor-based chat (live coding)
    ● Virtual Threads and Project Loom
    ● A Loom-based chat (live coding)
    Live coding with

    View Slide

  97. Write You a Chat

    View Slide

  98. @evacchi
    Server

    View Slide

  99. @evacchi
    Client Manager

    View Slide

  100. @evacchi
    Client Manager

    View Slide

  101. @evacchi
    Thou Shall Not Block!

    View Slide

  102. Loom

    View Slide

  103. @evacchi
    Green Threads
    ● in the Java 1.0 days, some JVMs "green" (user-mode) threads.
    ● The green threads of the 90s still had large, monolithic stacks.
    ● A product of their time
    ○ systems were single-core
    ○ OSes did not have thread support at all.
    https://www.infoq.com/articles/java-virtual-threads/

    View Slide

  104. @evacchi
    Virtual Threads
    ● Virtual threads: only superficial similarity to Green Threads
    ● More in common with user-mode threads in Go or Erlang
    ● However: semantically identical to java.lang.Thread

    View Slide

  105. @evacchi
    Virtual Threads
    ● Virtual threads: only superficial similarity to Green Threads
    ● More in common with user-mode threads in Go or Erlang
    ● However: semantically identical to java.lang.Thread

    View Slide

  106. @evacchi
    Green Threads
    ● Solaris 2.6 software
    ● the green threads library was user-level
    ● the Solaris system could process only one green thread at a time,
    ● Solaris handled the Java runtime as a many-to-one threading implementation
    ● Java applications could not interoperate with existing MT applications in the
    Solaris environment.
    ● Java threads could not run in parallel on multiprocessors.
    ● An MT Java application could not harness true OS concurrency for faster
    applications on either uniprocessors or multiprocessors.
    Green threads library was replaced with native Solaris threads for Java on the Solaris 2.6
    platform; this is carried forward on the Solaris 7 and Solaris 8 platforms.
    https://docs.oracle.com/cd/E19455-01/806-3461/6jck06gqe/

    View Slide

  107. @evacchi
    Loom
    https://wiki.openjdk.org/display/loom/Main
    “Project Loom is intended to explore, incubate and
    deliver Java VM features and APIs built on top of them
    for the purpose of supporting easy-to-use,
    high-throughput lightweight concurrency and new
    programming models on the Java platform.”

    View Slide

  108. @evacchi
    Loom
    ● Virtual Threads are mounted on platform threads
    (carrier threads)
    ● Yield in std library

    View Slide

  109. https://www.youtube.com/watch?v=449j7oKQVkc

    View Slide

  110. @evacchi
    Thou Shall Not Block!

    View Slide

  111. @evacchi
    Thou Shall Not Block!

    View Slide

  112. Write You
    a Loom Chat

    View Slide

  113. Game of Loom:
    implementation patterns and
    performance implications
    playing with virtual threads
    by Mario Fusco
    @mariofusco Learn More
    This Thursday!

    View Slide

  114. @evacchi
    bit.ly/actor19

    View Slide

  115. View Slide