Hi shankara,
Welcome to CodeRanch!
Please,
UseCodeTags. I've added code tags for you this time. Also, please try to write more readable code(using proper indentation etc.).
Now, coming to your problem, technically, with synchronized block, we don't
lock an object, but we
acquire a lock on an object. What this means is - if a
thread is having a lock on an object(that is - enters in synchronized block), then no other thread can acquire lock on the
same object unless the first thread releases the lock(that is - exits from synchronized block).
As stated above, you can acquire lock on any object. E.g. in your code, you are sending object of table class to both threads and you are synchronizing the code on 'this' (that is, current object of table class). You can synchronize on any other object (e.g. a
String, an Integer and so on).
Only important thing is - it should be
same object to prevent multiple threads entering in same synchronized block.
I hope this helps.