Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding in concurrent logic to help prevent ConcurrentModificationException #89

Open
wants to merge 2 commits into
base: transitclock-merge
Choose a base branch
from

Conversation

rjasmin-camsys
Copy link

Adding in concurrent logic to help prevent ConcurrentModificationException, also appears to have a very minor boon to performance.

…ption, also appears to have a very minor boon to performance.
Copy link
Member

@sheldonabrown sheldonabrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cool you investigated a new locking mechanism, but I don't understand how you view its behaviour differently than the existing synchronized (..) blocks. Some of the work here seems superfluous, and some of your unlocks aren't in finally clauses.

Can you take a pass at my questions and help me understand? Thanks!

// so that new IPC vehicle data will be created and cached and
// made available to the API.
VehicleDataCache.getInstance().updateVehicle(vehicleState);
l.unlock();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, if the updateVehicle(vehicleState) is at issue by being outside of the synchronized block, then consider moving it.

@@ -217,6 +220,7 @@ public Indices increment(long epochTime) {
}
}
}
l.unlock();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why a lock is needed here?

@@ -88,16 +90,19 @@ private static String threadNameWithCounter(String name) {
count++;
}
threadNameCountMap.put(name, count);
l.unlock();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the threadNameCountMap.put is causing the issue, consider moving it inside the synchronized block.

@@ -141,6 +146,7 @@ public void run() {
System.exit(-1);
}
} finally {
l.unlock();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, you really need to convince me this is necessary. Locking an entire thread seems completely unreasonable. I suspect you don't understand how this thread is used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove this and retest.

@@ -165,7 +167,7 @@ public void run() {
// filter
// the next one
avlReports.put(avlReport.getVehicleId(), avlReport);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it the avlReports.put(...) is the problem here, I suggest extending the synchronized (avlReports) block instead. The Reentrant lock doesn't give you anything different as I understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants