Over a million developers have joined DZone.

Is Your Java Eclipse Plugin Thread Safe?

DZone's Guide to

Is Your Java Eclipse Plugin Thread Safe?

A look at race conditions, what they are, and how they work inside Eclipse Luna.

· Java Zone ·
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

...Or Does It Contain Race Conditions?

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. https://en.wikipedia.org/wiki/Race_condition

We searched inside Eclipse for race conditions to see 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 jJava 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.



Concurrently Accessed Fields


Fields Traced








Volatile Fields


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 {
                    } catch (Exception e) {
                    // todo check if isEmpty is necessary
                    if (queue.isEmpty() || terminated) {


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

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.

java ,eclipse 4 ,race conditions

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}