WS-07-Multithreading-Basics-and-Hashing

This commit is contained in:
2026-05-24 23:43:28 +03:30
parent 83746b88f6
commit 160475f978
13 changed files with 180 additions and 109 deletions
@@ -1,10 +1,23 @@
package lecture.multithreading.timeout;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO
Scanner scanner = new Scanner(System.in);
System.out.println("you have 10 seconds: ");
System.out.println("enter your name: ");
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.setDaemon(true);
thread.start();
String name = scanner.nextLine();
System.out.println("Hello " + name);
scanner.close();
}
}
@@ -0,0 +1,20 @@
package lecture.multithreading.timeout;
public class MyRunnable implements Runnable{
@Override
public void run() {
for (int i = 0; i <= 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("thread was interrupted");
}
if(i==10){
System.out.println("time is up");
System.exit(0);
}
}
}
}