feat: Add comprehensive examples from multithreading and hashing lectures

This commit is contained in:
2026-05-24 15:46:45 +03:30
parent 6583799d9e
commit 83746b88f6
13 changed files with 314 additions and 39 deletions
@@ -0,0 +1,31 @@
package lecture.multithreading.basics;
public class IsAliveExample {
public static void main(String[] args) throws InterruptedException {
Thread worker = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("👷 Worker started...");
try {
Thread.sleep(15000); // Runs for 15 seconds
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("👷 The worker is done!");
}
});
System.out.println("before start: " + worker.isAlive()); // false
worker.start();
System.out.println("Immediately after start: " + worker.isAlive()); // true
Thread.sleep(1000); // We wait 1 second
System.out.println("After 1 second: " + worker.isAlive()); // true (still works)
worker.join(); // We wait for the worker to finish
System.out.println("After completion of work: " + worker.isAlive()); // false
}
}