Disadvantages of Scoped Values
- New feature: Because scoped values are a newer feature in Java, they have less documentation and support than more established features.
- Complexity: Scoped values can complicate coding, particularly for those who are unfamiliar with them.
- Performance overhead: Scoped values might cause some performance overhead, especially in high-concurrency applications. This overhead, however, is usually insignificant.
Scoped Values in Java
In Java, Scoped variables enable the exchange of immutable data across and between threads. This new API is implemented as an incubator preview feature in Java 20 as part of JEP 439. They are preferred over thread-local variables, especially when a large number of virtual threads are used. This is an API that is still in development.