Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tk.evilus;
- public class w02_2 extends Thread {
- public void run() {
- System.out.println("ID = "+this.getName());
- }
- public static void main(String[] args) {
- w02_2[] threads = new w02_2[101];
- for (int i=0; i<threads.length; i++) {
- threads[i] = new w02_2();
- threads[i].setName(Integer.toString(i));
- }
- for (int i=0; i<threads.length; i+=2) {
- threads[i].run();
- }
- while (true) {
- try {
- for (int i=0; i<threads.length; i+=2) {
- threads[i].join();
- }
- break;
- } catch (Exception e) {
- e.printStackTrace(System.out);
- }
- }
- for (int i=1; i<threads.length; i+=2) {
- threads[i].run();
- }
- while (true) {
- try {
- for (int i=1; i<threads.length; i+=2) {
- threads[i].join();
- }
- break;
- } catch (Exception e) {
- e.printStackTrace(System.out);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement