Skip to content

Commit 5712fa4

Browse files
authored
Update Singleton vs Prototype.md
1 parent 628fc39 commit 5712fa4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Basics of SpringBoot/Singleton vs Prototype.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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
20+
}
21+
```
122
# Prototype Scope
223
## Definition:
324

0 commit comments

Comments
 (0)