Quantcast
Channel: Java Threading - Synchronized code - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Java Threading - Synchronized code

$
0
0

Why do you have to specify, which object has locked a synchronized block of code?

You don't have to specify which object has locked a synchronized method as it is always locked by 'this' (I believe).

I have two questions:

  • Why can't you block a none static method with an object other than'this' ?
  • Why do you have to specify the object that has blockedsynchronized code?

I have read chapter nine of SCJP for Java 6, but I am still not clear on this.

I realize it is probably a basic question, but I am new to Threading.


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles



Latest Images