# Is it possible to synchronize the string type in Java?

Java 8Object Oriented ProgrammingProgramming

A thread is a piece of code (under execution) in a program, which executes a sub task of the process independently. independent process.

In other words, a thread is a light weight process which executes a piece of code independently.

If a process has multiple threads running independently at the same time (multi-threading) and if all of them trying to access a same resource an issue occurs.

To resolve this, Java provides synchronized blocks/ synchronized methods. If you define a resource (variable/object/array) inside a synchronized block or a synchronized method, if one thread is using/accessing it, other threads are not allowed to access.

synchronized (Lock1) {
}