Top "Synchronized" questions

A block or method is said to be 'synchronized' if entry to it is controlled by the Java `synchronized` keyword.

Java avoid race condition WITHOUT synchronized/lock

In order to avoid race condition, we can synchronize the write and access methods on the shared variables, to lock …

java multithreading concurrency race-condition synchronized
What happens when two threads call the same static method at the same time?

What happens when two threads call the same static method at the same time? For example: public static String someMethod(){ //…

java multithreading static synchronized
calling Thread.sleep() from synchronized context in Java

I have read that Thread.sleep() will pause the currently running thread for the time specified after which it goes …

java multithreading synchronized thread-sleep
Synchronized method calls itself recursively. Is this broken?

The point of this question is to illustrate that Java is not working as I expected. How would you expect …

java recursion synchronized
RecyclerView IndexOutOfBoundsException

Why exception execute when I removed some items in RecyclerView by using loop ? I used Collentions.synchronizedMap in adapter and …

android indexoutofboundsexception synchronized android-recyclerview
How to return a thread safe/immutable Collection in Java?

In the project I am coding, I need to return a thread safe and immutable view from a function. However, …

java list thread-safety synchronized unmodifiable
Can you safely synchronize on a Java method parameter?

Take this code: public class MyClass { private final Object _lock = new Object(); private final MyMutableClass _mutableObject = new MyMutableClass() public void …

java methods parameters locking synchronized
Why can't an abstract method be synchronized?

I was reading a thread from CodeRanch saying that abstract methods could not be synchronized due to the fact that …

java multithreading inheritance synchronized abstraction
Difference between Synchronized block with wait/notify and without them?

If I just use synchronized, not the wait/notify methods, will it still be thread-safe? What's the difference?

java multithreading wait synchronized notify
Singleton Pattern in Multi threaded environment

During my interview, interviewer started his question with singleton pattern. I wrote below. Then, he asked Shouldn't we check for …

java multithreading design-patterns singleton synchronized