Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V6126. Native synchronization used...
menu mobile close menu
Additional information
toggle menu Contents

V6126. Native synchronization used on high-level concurrency class.

Apr 17 2025

The analyzer has detected that a subclass of java.util.concurrent.locks.Lock, java.util.concurrent.locks.Condition, java.util.concurrent.locks.ReadWriteLock, and/or java.util.concurrent.locks.StampedLock is passed to the synchronized statement.

These classes belong to the category of high-level concurrency classes, and their use with synchronized is incorrect. Instead, it is recommended to use the locking mechanisms provided directly by these classes.

When synchronized is used with such objects, it creates two independent synchronization systems. One system is based on the object monitor (via synchronized), and the other is based on the internal locking mechanism of the class. This can lead to the following issues:

  • broken synchronization integrity;
  • race conditions;
  • deadlocks;
  • unexpected program behavior.

The incorrect code:

Lock lock = new ReentrantLock();

synchronized(lock) {
    ....
}

The fixed code:

Lock lock = new ReentrantLock();

lock.lock();
try {
    ....
} finally {
    lock.unlock();
}

This diagnostic is classified as:

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I want to join the test
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam