Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31e359ff87 |
@@ -1,13 +1,15 @@
|
||||
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 Only Have 10 Seconds...");
|
||||
System.out.print("Enter Your Name: ");
|
||||
System.out.println("you have 10 seconds: ");
|
||||
System.out.print("enter your name: ");
|
||||
|
||||
MyRunnable myRunnable = new MyRunnable();
|
||||
Thread thread = new Thread(myRunnable);
|
||||
@@ -15,8 +17,9 @@ public class Main {
|
||||
thread.start();
|
||||
|
||||
String name = scanner.nextLine();
|
||||
System.out.println("Hello " + name + "!");
|
||||
System.out.println("hello " + name);
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package lecture.multithreading.timeout;
|
||||
|
||||
public class MyRunnable implements Runnable {
|
||||
public class MyRunnable implements Runnable{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
public void run(){
|
||||
|
||||
for (int i = 1; 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("\nTime is Up!");
|
||||
if(i == 10){
|
||||
System.out.println("time is up");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user