added ex C
This commit is contained in:
parent
0cb00f057e
commit
104df9d3f8
28
src/exercicses/ex_c/SleepMessages.java
Normal file
28
src/exercicses/ex_c/SleepMessages.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package exercicses.ex_c;
|
||||||
|
|
||||||
|
public class SleepMessages implements Runnable {
|
||||||
|
public String[] song = {
|
||||||
|
"Georges Brassens (1964) - Les Copains d'abord",
|
||||||
|
"Non, ce n'était pas le radeau",
|
||||||
|
"De la Méduse, ce bateau",
|
||||||
|
"Qu'on se le dise au fond des ports",
|
||||||
|
"Dise au fond des ports",
|
||||||
|
"Il naviguait en père peinard",
|
||||||
|
"Sur la grand - mare des canards",
|
||||||
|
"Et s'appelait les Copains d'abord",
|
||||||
|
"Les Copains d'abord"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (String msg : song) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
System.out.println(msg);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
src/exercicses/ex_c/TestingSleep.java
Normal file
14
src/exercicses/ex_c/TestingSleep.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package exercicses.ex_c;
|
||||||
|
|
||||||
|
public class TestingSleep {
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
Thread thread = new Thread(new SleepMessages());
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
System.out.println("Waiting 3 seconds");
|
||||||
|
Thread.sleep(3000);
|
||||||
|
System.out.println("Stopping thread");
|
||||||
|
thread.interrupt();
|
||||||
|
System.out.println("Stopped");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user