which is better approach to use class level lock or instance level lock on static block in java
If you create a lock on the class, then all instances of the class will share the lock. If you have 1 instance, there won't be any difference. If you have thousands of instances, they will all use the very same lock. If many threads try to acquire the lock at the same time, they will block each other out.f you create the lock on the instance, then several threads can execute the protected code as long as they operate on different instances. Here, the threads don't block each other. So this approach performs better.