I have two threads to sell tickets.

```
public class MyThread {

    public static void main(String[] args) {

        Ticket ticket = new Ticket();

        Thread thread1 = new Thread(()->{
            for (int i = 0; i < 30; i++) {
                ticket.sell();
            } }, "A");

        thread1.start();
        Thread thread2 = new Thread(()->{
            for (int i = 0; i < 30; i++) {
                ticket.sell();
            } }, "B");
        thread2.start();

    }

}

class Ticket {

    private Integer num = 20 ;

    private Object obj = new Object();

    public void sell() {

        // why shouldn't I use "num" as a monitor object ?
        // I thought "num" is unique among two threads.
        synchronized ( num ) { 

            if (this.num >= 0) {
                System.out.println(Thread.currentThread().getName() + " sells " + this.num + "th ticket");
                this.num--;
            }
        }
    }
}

```

The output will be wrong if I use `num` as a monitor object.

But if I use `obj` as a monitor object, the output will be correct.

What's the difference between using `num` and using `obj` ?

===============================================

And why does it still not work if I use `(Object)num` as a monitor object ?

```
class Ticket {

    private int num = 20 ;

    private Object obj = new Object();

    public void sell() {

        // Can I use (Object)num as a monitor object ?
        synchronized ( (Object)num ) { 

            if (this.num >= 0) {
                System.out.println(Thread.currentThread().getName() + " sells " + this.num + "th ticket");
                this.num--;
            }
        }
    }
}

```