Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lista5nowa;
- class Watek extends Thread {
- int id;
- public Watek(int id) {
- this.id = id;
- }
- public void run() {
- // System.out.println("Watek " + id);
- System.out.println(this.getName());
- try {
- sleep(1000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public class zad {
- public static void main(String[] args) {
- final int N = 20;
- Watek[] threads = new Watek[N];
- for (int i = 0; i < N; i++) {
- threads[i] = new Watek(i);
- }
- int i;
- for (i = 0; i < N; i++) {
- if (i % 2 == 0) {
- threads[i].start();
- try {
- threads[i].join();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- for (i = 0; i < N; i++) {
- if (i % 2 != 0) {
- threads[i].start();
- try {
- threads[i].join();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement