The output

Report a typo

Sort the output of the code below:

public class Main {
    private static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        class MyRunnable implements Runnable {

            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                System.out.println(name + " BEFORE: " + threadLocal.get());

                threadLocal.set(name + " value");
                System.out.println(name + " AFTER: " + threadLocal.get());
            }
        };

        threadLocal.set("threadLocal main value");

        Thread thread1 = new Thread(new MyRunnable(), "first_thread");
        Thread thread2 = new Thread(new MyRunnable(), "second_thread");

        // first
        thread1.start();
        thread1.join();
        // second
        thread2.start();
        thread2.join();

        System.out.println("From the main thread: " + threadLocal.get());
    }
}
Put the items in the correct order
first_thread AFTER: first_thread value
From the main thread: threadLocal main value
first_thread BEFORE: null
second_thread AFTER: second_thread value
second_thread BEFORE: null
___

Create a free account to access the full topic