You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Basics of SpringBoot/Singleton vs Prototype.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,24 @@
1
+
# Singleton Scope
2
+
## Definition:
3
+
4
+
* A singleton scope means that only one instance of a bean is created and used throughout the entire application context. This instance is shared across the application.
5
+
## Characteristics:
6
+
7
+
* Single Instance: Only one instance of the bean is created, and this instance is reused throughout the application.
8
+
* Memory Efficiency: It saves memory and resources since only one instance is created and managed.
9
+
* Shared State: Any state or changes to the bean are shared across all consumers. This can be problematic if the bean maintains mutable state, as changes can affect all parts of the application using the bean.
10
+
## Use Cases:
11
+
12
+
* Stateless Beans: Ideal for beans that are stateless or where shared state is acceptable.
13
+
* Performance: Useful for beans that are expensive to create, such as database connections or configuration objects.
14
+
## example
15
+
```
16
+
@Component
17
+
@Scope("singleton")
18
+
public class SingletonBean {
19
+
// Bean instance is shared across the application context
0 commit comments