
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Can a constructor be synchronized in Java?
No, a constructor cannot be synchronized in Java. The JVM ensures that only one thread can invoke a constructor call at a given point in time. That is why no need to declare a constructor as synchronized and it is illegal in Java. However, we can use synchronized blocks inside a constructor.
If we are trying to put a synchronized keyword before a constructor, the compiler says that "error: modifier synchronized not allowed here".
Example
public class SynchronizedConstructorTest { // declaration of synchronized constructor public synchronized SynchronizedConstructorTest() { System.out.println("Synchronized Constructor"); } public static void main(String args[]) { SynchronizedConstructorTest test = new SynchronizedConstructorTest(); } }
Output
SynchronizedConstructorTest.java:3: error: modifier synchronized not allowed here public synchronized SynchronizedConstructorTest() { ^ 1 error
- Related Articles
- Can a constructor be overridden in java?
- Can a constructor be made final in Java?
- When can we use Synchronized blocks in Java?
- Why a constructor cannot be final in Java?
- Can a constructor throw an exception in Java?
- Can we define a static constructor in Java?
- Can we have a constructor private in java?
- Can constructor throw exceptions in Java?
- synchronized Keyword in Java
- Why constructor cannot be final in Java
- Can we declare a constructor as private in Java?
- Can we call a constructor directly from a method in java?
- Can we declare constructor as final in java?
- Can we initialize static variables in a default constructor in Java?
- Where and how can I create a private constructor in Java?

Advertisements