EJB threadsafe Singleton bean VS EJB threadsafe Stateless bean

2.7k views Asked by At

This question is to compare EJB Singleton bean and Stateless bean in the case both them are Threadsafe (No state holding OR Readonly State). I thought they can be used for the same purpose ( in case they are threadsafe). If I understand wrong, can someone let me know what are differences between them in my case? When to use which one? Thanks.

1

There are 1 answers

4
remigio On

Singletons maintain their state across client invocations, so there is no reason for using them to access read-only state or for no state holding processing. Common scenarios for singletons are configuration reading and/or initialization tasks at application startup or shutdown, or accessing shared resources in a thread-safe way. Moreover there is a difference in performance and scalability, singleton beans are instantiated only once and process every single request sequentially, whereas stateless beans can be pooled and can process more requests concurrently.