When reading document about stateful and stateless bean in Java, I kind of understand but there is this general case making me confusing:
- I have a web service, it needs in-memory data to process request, and this data is added up to the memory through web service requests, not by loading from database. To make this simple, please think of the web service provides methods to process students’ data, but at first, the data of all students in a class need to be put into the memory, assuming that the data is just temporarily so we don’t put and load them from any database.
- Assuming at the first step we have 3 clients call to web service to add many students’ data into the web service.
- At the second step, each client calls to a web service method, says int getRank(student), this method implementation is just looping through all students’ data and check the rank of the inputted student based on his mark on particular subject. And that’s all, an integer number will be returned and we do not need to store any client-service related thing so I guess we don’t need a stateful bean. However, since after each call to put student data to the service, that data need to be remained in the memory, it seems we have some kind of stateful thing here but I don’t know what it is called and is this make the service called stateful web service.
Thank you for any idea.
This sounds like “caching” to me. You periodically update a chunk of data that resides in memory to save the network latency; it’s possible because the chunk is not overly large.
I’d say that any standard caching solution would do. You just have to be careful when loading the values in to ensure that read operations aren’t going on and to make sure that it’s an orderly process. Multiple clients should not have any opportunity to harm anyone else’s data.
I would agree – you don’t need stateful session beans. You need caching.