I'm learning work with `Thread` in `Java`. 
I am trying to write a program that will have two threads.
Each thread will write your name in the cycle.
In `Main` run cycle will generate numbers ( 0 , 9 ).
When it generates an odd number, wait the thread 1 ( even - thread 2 ) .
If a thread will sleep and wake him up .
**The problem is that when I call wait , the program freezes .**
Code:

```
import java.util.Random;

public class TestClass {

    public static void main(String[] args) throws InterruptedException {

        myThread one = new myThread("Thread one");
        myThread two = new myThread("Thread two");

        one.start();
        two.start();

        Random random = new Random();

        for (int i = 0; i < 10; i++) {
            int rnd = random.nextInt(10);
            if (rnd % 2 == 0) {
                synchronized (two) {
                    two.wait(); // first loop - freez
                }
            } else {
                synchronized (one) {
                    one.wait();
                }
            }
        }

    }

}

class myThread extends Thread {

    private boolean canIRun = true;
    private final String name;

    myThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        while (canIRun) {
            System.out.println("My name is: " + name);
        }
    }

}

```