Using Object o = new Object ()

I used -

Object o = new Object(); 

to synchronize threads, and this is useful because closing the lock object encapsulates the lock, so the client code cannot acquire it, but does not know another use for this. What are the other reasons why the object-object is not abstract? In what other situation can I use the above code?

+4
source share
1 answer

The main practical utility of simply creating a shared object would be to use blocking capabilities (e.g. wait() and notify() ). But it may be what you are talking about, a denial of service, as using these methods can help manage flows and potentially help protect DoS. (but this is really application specific and not inherent in the purpose of these methods in Object)

The reason (s) why Object is not abstract is already discussed in detail here:

Why is java.lang.Object not abstract?

+3
source

Source: https://habr.com/ru/post/1344436/


All Articles