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,33 @@
package lecture.multithreading.basics;
public class StandardPattern {
public static void main(String[] args) throws InterruptedException {
Thread worker = new Thread(new Runnable() {
@Override
public void run() {
// Both together: checking in the loop
while (!Thread.currentThread().isInterrupted()) {
// doing work
System.out.println("Working...");
// Work simulation
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// When we are interrupted in sleep
System.out.println("Interrupted during sleep!");
Thread.currentThread().interrupt(); // Reset status
// break;
}
}
System.out.println("Thread stopped!");
}
});
worker.start();
Thread.sleep(1000);
worker.interrupt(); // Send a sign
worker.join();
}
}