class Lock {

    public synchronized void lock() {
        while (this.lockOwner != null && !this.lockOwner.equals(Thread.currentThread())) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.lockOwner = Thread.currentThread();
    }

}