Premraj
Premraj

Reputation: 7902

use of Object o = new Object()

I have used -

Object o = new Object(); 

for thread synchronizations and this is helpful because making the lock object private encapsulates the lock so that client code cannot acquire it, but don't know any other use of this.
What are the other reasons that Object class is not abstract? In which other situation I can use above code?

Upvotes: 4

Views: 3808

Answers (1)

kvista
kvista

Reputation: 5059

The main practical utility of just creating a generic object would be to leverage its locking capabilities (e.g., wait() and notify()). But this may be what you are referring to by "denial of service", since use of these methods can help manage threads and potentially help in a defense of DoS. (but that is really app specific, and not inherent to the purpose of these methods within Object)

The reason(s) why Object is not abstract is already discussed at length here:

Why java.lang.Object is not abstract?

Upvotes: 3

Related Questions