java - Is checksum a good way to see if table has been modified in MySQL? -
i'm developing application in java connects mysql database using jdbc, , displays records in jtable. application going run more 1 user @ time , i'm trying implement way see if table has been modified. eg if user 1 modifies column such stock level, , user 2 tries access same record tries change based on level before user 1 interacts.
at moment i'm storing checksum of table that's being displayed variable , when user tries modify record check whether stored checksum same 1 generated before edit.
as i'm new i'm not sure if correct way or not; have no experience in matter.
calculating checksum of entire table seems heavy-handed solution , wouldn't scale in long term. there multiple ways of handling core theme little work possible ensure can scale number of users increase. imagine implementing checksum based solution on table million rows continuously updated hundreds of users!
one of solutions (which requires minimal re-work) "check" stock name against value updated. in background, you'll fire across query table see if data "that particular stock" has been updated after table populated. if yes, can warn user or mark updated cell dirty indicate that value has changed. problem here query won't fired off till user tries save updated value. or poll database avoid again hardly efficient solution.
as more robust solution, recommend using database implements native "push notifications" connected clients. redis nosql database comes mind this.
another tried , tested technique forgo direct database connection , use middleware layer messaging queue (e.g. rabbitmq). message queues enable design of systems communicate using message. e.g. every update stock value in jtable sent across message "update database queue". once update done, message sent across "update notification queue" clients connected. enable of them know value of given stock has been updated , act accordingly. advantage solution keep existing stack (java, mysql) , can implement notifications without polling db , killing it.
Comments
Post a Comment