1bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz/*
2bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * Copyright (C) 2014 The Android Open Source Project
3bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz *
4bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * Licensed under the Apache License, Version 2.0 (the "License");
5bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * you may not use this file except in compliance with the License.
6bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * You may obtain a copy of the License at
7bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz *
8bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz *      http://www.apache.org/licenses/LICENSE-2.0
9bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz *
10bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * Unless required by applicable law or agreed to in writing, software
11bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * distributed under the License is distributed on an "AS IS" BASIS,
12bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * See the License for the specific language governing permissions and
14bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz * limitations under the License.
15bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz */
16bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz
17bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertzimport java.util.ArrayList;
18bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz
19bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertzpublic class Main {
20bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz    static class ThreadRunnable implements Runnable {
21bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        public void run() {
22bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            for (int i = 0; i < 1000; ++i) {
23bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz                doNothing();
24bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            }
25bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        }
26bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz
27bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        private void doNothing() {}
28bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz    }
29bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz
30bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz    public static void main(String[] args) {
31bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        ArrayList<Thread> threads = new ArrayList<Thread>();
32bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        for (int i = 0; i < 10; ++i) {
33bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            threads.add(new Thread(new ThreadRunnable(), "TestThread-" + i));
34bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        }
35bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz
36bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        for (Thread t : threads) {
37bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            t.start();
38bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        }
39bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz
40bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        for (Thread t : threads) {
41bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            try {
42bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz                t.join();
43bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            } catch (InterruptedException e) {
44bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz                System.out.println("Thread " + t.getName() + " has been interrupted");
45bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz            }
46bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz        }
47bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz    }
48bae182cbc6adc8796154162a87fc54ae804e0469Sebastien Hertz}
49