Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Learn Java multithreading in 8 minutes! ๐Ÿงถ

42.4K views on YouTube

#java #javatutorial #javacourse

public class Main {
public static void main(String[] args) {

// Multithreading = Enables a program to run multiple threads concurrently
// (Thread = A set of instructions that run independently)
// Useful for background tasks or time-consuming operations

Thread thread1 = new Thread(new MyRunnable(“PING”));
Thread thread2 = new Thread(new MyRunnable(“PONG”));

System.out.println(“GAME START!”);

thread1.start();
thread2.start();

try {
thread1.join();
thread2.join();
}
catch (InterruptedException e) {
System.out.println(“Main thread was interrupted”);
}

System.out.println(“GAME OVER!”);
}
}