Java.Multithreading.Can new instances of a class be created while a static synchronized method is executing?

Yes, new instances of a class can be created while a static synchronized method is executing.

Let’s break it down:


🔒 static synchronized method

  • It locks on the Class object, not on an instance.
  • So, if thread A is executing a static synchronized method, it holds the class-level lock.

💡 Creating new instances

  • Creating an object via new MyClass() does not require any lock.
  • It’s simply calling a constructor, which is not synchronized by default.
  • Therefore, other threads can create new instances of the class, even while the static synchronized method is running.
This entry was posted in Без рубрики. Bookmark the permalink.