Skip to content

Adding in concurrent logic to help prevent ConcurrentModificationException#89

Open
rjasmin-camsys wants to merge 2 commits intotransitclock-mergefrom
MET-247-concurrent-mod
Open

Adding in concurrent logic to help prevent ConcurrentModificationException#89
rjasmin-camsys wants to merge 2 commits intotransitclock-mergefrom
MET-247-concurrent-mod

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

@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();

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.

}
}
}
l.unlock();

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?

count++;
}
threadNameCountMap.put(name, count);
l.unlock();

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.

System.exit(-1);
}
} finally {
l.unlock();

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.

// the next one
avlReports.put(avlReport.getVehicleId(), avlReport);
}

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