My goal is to create Java EE web service, which will take concurrently thousands (or more in future) requests and must store data from requests in list or similar structure. I want to store objects from requests in memory, but this is not obligatory. Some object will be extracted from every request and added to chosen data structure. Web service will have two operations: add to structure and remove from structure. Removal request will contain values of object instance variables. Probably it will be unique ID or other one or more instance variables. There will be always one object to remove (or 0 if request is not valid). Object with equal instance variable(s) value will be removed.
My thought is to use two EJBs. First would be @Stateless and exposed as web service. It would extract object from request and call second EJB to add or remove requested object from data structure. Second EJB would be @Singleton and would have instance variable ArrayList<> of objects extracted from requests. As I said it doesn't have to be ArrayList or List at all.
I have also thought about using one EJB, which would have to be @WebService @Singleton, but documentation says that this combination is "possible, but ... not defined by this specification."
Arjan, your requirement is not fully clear. Assuming you are building a high load application > 1000 request per second I would do:
Servlet-processing
Singleton EJB
TimerEJB
Benefit of the solution:
Drawback: