4
Exécution en parallèle
- public class TwoThreadsTest {
- public static void main(String[] args) {
- (new SimpleThread("Paris")).start();
- (new SimpleThread("Tokyo")).start();
- }
- }
$ javac TwoThreadsTest.java
$ java TwoThreadsTest
0 Paris - 3
0 Tokyo - 3
1 Tokyo - 3
1 Paris - 3
2 Paris - 3
2 Tokyo - 3
3 Tokyo - 3
4 Tokyo - 3
3 Paris - 3
...
9 Tokyo - 3
DONE! Tokyo
8 Paris - 2
9 Paris - 2
DONE! Paris
- public class TwoRunnablesTest {
- public static void main(String[] args) {
- System.out.println(Thread.activeCount());
- (new Thread(new SimpleRunnable("Paris"))).start();
- (new Thread(new SimpleRunnable("Tokyo"))).start();
- System.out.println("DONE! " + "main");
- }
- }
$ javac TwoRunnablesTest.java
$ java TwoRunnablesTest
1
0 Paris - 3
DONE! main
0 Tokyo - 3
1 Paris - 3
1 Tokyo - 3
2 Paris - 3
2 Tokyo - 3
3 Tokyo - 3
4 Tokyo - 3
3 Paris - 3
...
9 Paris - 3
9 Tokyo - 3
DONE! Tokyo
DONE! Paris
Commentaires