Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a98339b5ce | ||
|
|
8406ceaaa8 |
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,20 @@
|
||||
package lecture.multithreading.timeout;
|
||||
|
||||
public class MyRunnable implements Runnable{
|
||||
public class MyRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
|
||||
for (int i = 1; i <= 10 ; i++){
|
||||
public void run() {
|
||||
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");
|
||||
if (i == 10) {
|
||||
System.out.println("\nTime is Up!");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user