Author SHA1 Message Date
Soroush a98339b5ce Workshop-7 2026-06-01 18:41:41 +03:30
Soroush 8406ceaaa8 Workshop-7 2026-06-01 18:39:19 +03:30
2 changed files with 11 additions and 16 deletions
@@ -1,15 +1,13 @@
package lecture.multithreading.timeout;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("you have 10 seconds: ");
System.out.print("enter your name: ");
System.out.println("You Only Have 10 Seconds...");
System.out.print("Enter Your Name: ");
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
@@ -17,9 +15,8 @@ public class Main {
thread.start();
String name = scanner.nextLine();
System.out.println("hello " + name);
System.out.println("Hello " + name + "!");
scanner.close();
}
}
@@ -4,19 +4,17 @@ public class MyRunnable implements Runnable{
@Override
public void run() {
for (int i = 1; i <= 10 ; i++){
for (int i = 0; i <= 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("thread was interrupted");
System.out.println("Thread Was Interrupted");
}
if (i == 10) {
System.out.println("time is up");
System.out.println("\nTime is Up!");
System.exit(0);
}
}
}
}