Java EE concurrency & locking

佐手、 提交于 2019-12-05 12:45:10

If you are looking for performance, no locking, etc. I would suggest to have another table: (word, timestamp). Your MDBs will just insert the word and the timestamp. Another process will count and update the table with the totals.

This sounds like it needs to be solved within the database by choosing the correct transaction isolation level - repeatable read should be sufficient.

What you need is a book about databases, focusing on transactions.

Do you mean that multiple instances are processing the same message, or that the same word is used in different messages? If it is the same message, then you should be using a queue instead of a topic. This, of course does not solve the issue of the same word in multiple messages. For that case, you can follow the advice of @Michael Borgwardt and @Vitaly Polonetsky.

Another option, outside of the database, would be to have different MDB instances handle words starting with a set of letters. This could be easily accomplished with selectors. Then there would only be a single MDB handling any particular word, but processing is still split amongst multiple instances to increase performance. I am not claiming this is a better alternative, but just a different one that supports pretty simple queue based processing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!