I am trying to get the number of customer who lived in newyork and display on my page. But some doubt in my mind, which way is best to worst, Like stateless, stateful and singleton ejb? Any idea, which way i have to implement my application.
1 Answers
In this case it would be Stateless. As long as there is no state accross several invocations there is no need for a Stateful Bean. A singleton could be a bottleneck, as i would not use a method like getCustomersinNewYork() but getCustomers(City city), and a Singleton is only one instance which should be used to synchronize. But it is possible to have the method concurrent and store a Map with results for each City - but consider you need to handle the concurrency.
From my point of view I would keep the application stateless and let the StatelessBean calcuate the number of customers per city for each request. If there is a need to enhance the performance because the requests are repeated I would use a cache like Infinispan to store that - i.e. with expiration to recalculate the number from time to time or let it drop it not used for longer.
Make sense?

- 347
- 1
- 6