Skip to content

Commit 23680ff

Browse files
authored
Create Singleton vs Prototype
1 parent 3f4b437 commit 23680ff

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Prototype Scope
2+
## Definition:
3+
4+
* A prototype scope means that a new instance of the bean is created each time it is requested. Each consumer gets a unique instance.
5+
## Characteristics:
6+
7+
## Multiple Instances: A new instance is created every time the bean is requested from the application context.
8+
## Memory Usage: Can consume more memory and resources since multiple instances may be created, especially if the bean is requested frequently.
9+
## No Shared State: Each instance is independent, so changes to one instance do not affect others. This is useful for beans that need to maintain state that is unique per request or user.
10+
## Use Cases:
11+
* Stateful Beans: Ideal for beans that need to maintain unique state for each consumer or interaction.
12+
* Transient Beans: Useful when beans are short-lived and their state should not be shared.
13+
## example
14+
```
15+
@Component
16+
@Scope("prototype")
17+
public class PrototypeBean {
18+
// A new instance is created each time the bean is requested
19+
}
20+
```

0 commit comments

Comments
 (0)