-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: transitclock-merge
Are you sure you want to change the base?
Conversation
…ption, also appears to have a very minor boon to performance.
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | |||
} | |||
|
There was a problem hiding this comment.
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.
Adding in concurrent logic to help prevent ConcurrentModificationException, also appears to have a very minor boon to performance.