Skip to content

Closes issue #38902 #38917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,99 @@ Generally, you will not need to use `spring-boot-loader` directly but work with
The spring-boot-devtools module provides additional development-time features, such as automatic restarts, for a smoother application development experience.
Developer tools are automatically disabled when running a fully packaged application.

### ${\color{red} \space Virtual \space Threads \space Limitations \space and \space Best \space Practices \space in \space Spring \space Boot}$

### Warning: Potential Risks of Incorrect Virtual Thread Usage

Virtual threads in Spring Boot offer concurrent execution benefits but come with specific risks and limitations when used incorrectly:

1. **External Resource Overload:** Excessive concurrent virtual threads might strain external resources like database connections or file I/O operations. This can lead to contention, depletion, or performance degradation when the number of threads surpasses the capacity of these resources.

2. **Thread Starvation:** Uncontrolled creation of virtual threads can cause thread starvation, impacting system stability due to increased context switching and resource contention, ultimately affecting performance.

3. **Blocking Operations Impact:** Operations that block for extended periods, like synchronous blocking I/O or long-running tasks, might nullify the benefits of virtual threads by causing delays and potentially blocking other threads.

### Examples of Anti-Patterns and Potential Issues

Certain Spring modules might exacerbate these problems:
- **Spring JDBC or JPA:** Uncontrolled virtual threads might overload database connections, leading to bottlenecks or connection pool exhaustion.
- **Spring Web:** Concurrently handling requests using virtual threads might overload I/O-bound operations, affecting response times or causing bottlenecks.

### Quarkus Insight on Virtual Threads

Quarkus, a related framework, highlights the limitations and risks of virtual threads in concurrent environments, cautioning against unchecked usage due to potential resource constraints and scalability issues.

### Lack of Fine-Tuning in Spring Boot for Virtual Threads

Spring Boot lacks extensive fine-tuning options for virtual threads, necessitating careful consideration and strategic usage.

### Proposed Annotations for Virtual Threads

Consider introducing annotations like:
- **@RunOnVirtualThread:** Marks methods for execution on virtual threads.
- **@VirtualThreadSafe:** Ensures thread safety in virtual thread environments.
- **@NotVirtualThreadSafe:** Marks components or methods not suitable for virtual threads.

### Emphasizing Careful Usage and Thorough Testing

Before adopting virtual threads extensively, thoroughly test applications under various loads and scenarios to identify bottlenecks and resource constraints. Monitor thread usage and resource consumption regularly.

### Cautionary Approach

Excessive advertising of virtual threads might overlook the associated risks. Emphasize a cautious approach, encouraging users to consider the limitations and employ them judiciously.

### Adding Custom MimeMappings
**Step 1: Identify the MimeMappings File**

Locate the configuration file responsible for MimeMappings. Typically, it's named web.xml or similar.

**Step 2: Edit the MimeMappings**

Open the identified configuration file.

Look for the <mime-mapping> section or similar entries.

To add a new MimeMapping, use the following xml format:
<mime-mapping>
<extension>[FILE_EXTENSION]</extension>
<mime-type>[MIME_TYPE]</mime-type>
</mime-mapping>

Replace [FILE_EXTENSION] with the file extension (e.g., pdf, docx) and [MIME_TYPE] with the corresponding MIME type (e.g., application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document).

Save the changes to the configuration file.

**Step 3: Restart the Application (if required)**

If the changes to the configuration file require a server/application restart, perform the necessary steps to restart the application.

### Configuring MimeMappings Using Properties
**Step 1: Identify Properties File**

Locate the properties file used for configuring your application.


**Step 2: Add MimeMappings Properties**
Open the properties file.

**Add or modify properties related to MimeMappings using the following css format:**

mimeMappings.[FILE_EXTENSION]=[MIME_TYPE]
Replace [FILE_EXTENSION] with the file extension (e.g., pdf, docx) and [MIME_TYPE] with the corresponding MIME type (e.g., application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document).

**For example (bash):**

`mimeMappings.pdf=application/pdf
mimeMappings.docx=application/vnd.openxmlformats-officedocument.wordprocessingml.document
Save the changes to the properties file.`

**Step 3: Load Properties in Application**

Ensure that the application loads and utilizes these properties during runtime. This may involve a configuration setup within your application codebase to read and apply these properties for MimeMappings.

**Step 4: Restart the Application (if required)**

If changes to the properties file necessitate a server/application restart, proceed to restart the application accordingly.


== Guides
Expand Down