#Is nested Synchronization needed? (image related)

1 messages · Page 1 of 1 (latest)

ancient sinew
#

In the attached image, is there any particular reason the "synchronized(this)" needs to be included inside a synchronized method?
from what i understand, the synchronized keyword already makes sure that piece of code can only be run by a single thread, so the nested one seems very redundant

burnt torrentBOT
#

<@&987246399047479336> please have a look, thanks.

steady obsidian
#

you are correct

#

this is equivalent to

#
synchronized (this) {
    synchronized (this) {

    }
}
#

which is redundant

#

I will say there are reasons to not use synchronized (this)

#

and even more reasons to not use wait/notify/notifyAll

ancient sinew
#

thanks for answering

#

teacher wont respond to emails and stuff like this appeared many times in the pdfs

steady obsidian
#

also e.printStackTrace() isn't what you should do with an InterruptedException usually

ancient sinew
steady obsidian
#

throw new RuntimeException(e);

ancient sinew
#

aight 👍

steady obsidian
#

java concurrency in practice i've heard is a good book on that

ancient sinew
#

thanks for informing me, ill take a look someday

#

is there anything i need to do now or do i just leave this post be?

sturdy night
#

you can close this with /help-thread close if you dont have any more questions :)