Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a98339b5ce | ||
|
|
8406ceaaa8 |
@@ -1,15 +1,13 @@
|
|||||||
package lecture.multithreading.timeout;
|
package lecture.multithreading.timeout;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
System.out.println("you have 10 seconds: ");
|
System.out.println("You Only Have 10 Seconds...");
|
||||||
System.out.print("enter your name: ");
|
System.out.print("Enter Your Name: ");
|
||||||
|
|
||||||
MyRunnable myRunnable = new MyRunnable();
|
MyRunnable myRunnable = new MyRunnable();
|
||||||
Thread thread = new Thread(myRunnable);
|
Thread thread = new Thread(myRunnable);
|
||||||
@@ -17,9 +15,8 @@ public class Main {
|
|||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
String name = scanner.nextLine();
|
String name = scanner.nextLine();
|
||||||
System.out.println("hello " + name);
|
System.out.println("Hello " + name + "!");
|
||||||
|
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,19 +4,17 @@ public class MyRunnable implements Runnable{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
for (int i = 0; i <= 10; i++) {
|
||||||
for (int i = 1; i <= 10 ; i++){
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.out.println("thread was interrupted");
|
System.out.println("Thread Was Interrupted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 10) {
|
if (i == 10) {
|
||||||
System.out.println("time is up");
|
System.out.println("\nTime is Up!");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user