Is your java eclipse plugin thread safe?

December 12, 2015

Or does it contain race conditions?

According to wikipedia:
A race condition happens when the outcome of the program depends on the sequence or timing of other uncontrollable events. It becomes a bug when events do not happen in the order the programmer intended
We searched inside eclipse for race conditions to see what are the most common types of race conditions inside eclipse and its plugins.


The following types of race conditions were found by vmlens inside eclipse luna during startup and debugging of a java project:

No synchronization at all

The most common cause for race conditions was accessing the same field from different threads without any synchronization at all.
Object Count
Concurrently Accessed Fields 2065
Fields Traced 27114
Monitors 7162
Locks 427
Threads 52
Volatile Fields 2836
During this run 2065 different fields were accessed by more than one thread, 4 of them without synchronization.

2836 volatile fields were used. For 3 more fields it would have been necessary to declare them as volatile. This leads to the second type of race conditions found, visibility problems.


A field is accessed by many threads, but not declared as volatile.

The jvm does not directly write field updates into the main memory but first in registers or a cache of your cpu. As long as your program is running on one core of your pc, this is not a problem. But if the threads runs on different cores, they probably will not see the updates to the fields.

This problem appears most often with boolean flags. Like the terminated field of org.eclipse.equinox.internal.util.impl.tpt.timer.TimerImpl in the run method:

public void run() { TimerQueueNode n = null; while (!terminated) { synchronized (sync) { if (n == null && queue.isEmpty()) { try { sync.wait(); } catch (Exception e) { } // todo check if isEmpty is necessary if (queue.isEmpty() || terminated) { continue; } } }


For 2065 concurrently accessed fields, vmlens found 7 race conditions. All other were correctly synchronized by 7162 monitors or declared as volatile.

testing multi-threaded applications on the JVM made easy


© 2020 vmlens Legal Notice Privacy Policy