Hi Jofer,
Please do not post your entire locking solution. Locking is worth 20% of the assignment, and so each person should work on it on their own. If another candidate could just copy your entire solution, then they have just gained a lot of marks without doing any work. This just lowers the value of the certification.
I have therefore removed the unlock() method from your posted code. Most people can see where you are going from the lock() method alone, but anyone trying to copy your code would still have to work out how to implement the unlock() method themselves - it is not difficult, but they would have to have some idea of what they were doing.
As for your code: this should be thread safe, as long as you only have one instance of lockMap for your application.
Please note that swallowing the InterruptedException is a really bad idea -
you should never just hide an exception in this way. If you have code like that in your submitted application you could easily loose marks for it.
Doesn't your lock method have to throw some exceptions?
Regards, Andrew