How do you synchronize java?

Java

1 answer

Answer

1133859

2026-08-17 10:26

+ Follow

Synchronizaion is the process by which only one Thread can access an object at a time,until and unless thread releases it's lock no other thread can acess the object. there are two forms of syncronization method and statement.

to make a method synchronized just add the keyWord synchronized to the signature ie: public synchronized void increment() {

c++;

}

to create syncrhonized statements are like this:

synchronized(this) {

lastName = name;

nameCount++;

}

note: constructors can not be syncronized

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.