Microsoft Visual Studio Code for Java Now Supports Virtual Threads
- By David Ramel
- November 1, 2022
The October update of Microsoft's Visual Studio Code (VS Code) for Java has arrived with lots of improvements in the code editing and debugging experience, thanks to support for the recently released Java 19, which included a preview of Virtual Threads and Structured Concurrency, part of Project Loom.
The main goal of Project Loom is to support a high-throughput, lightweight concurrency model in Java by exploring and incubating JVM features for the implementation of lightweight, user-mode threads or fibers—thus the project's name.
"Virtual threads are designed to significantly boost the scalability of concurrent Java programming while making little change to the current API," said Nick Zhu, senior program manager in the Developer Division at Microsoft, in a blog post. "In our September release we have enabled the support for virtual threads in our Java debugger. Note that you will need to install JDK 19 to use this feature."
Debugging in Java on VS Code is further improved with new functionality that provides a visual indicator for inline breakpoints in a line of code.
"Now when you set a breakpoint on this line, Visual Studio Code will automatically identify the lambda expressions in this line, and visualize them with grey dots," Zhu explained. "If you want to further set inline breakpoints on those lambda expressions, you can directly click on those grey dots, and the grey dots will turn into red dots like normal breakpoints, then the debugger will stop at these breakpoints during the code execution. This will provide you much easier debugging experience for these lambda expressions."
Along with enhancing debugging, the dev team also implemented some code editing improvements concerning convenient Lombok operations when a user clicks on the Code Action lightbulb that triggers Quick Fixes.
Project Lombok, which received full support in the July 2022 update to Microsoft's Java on VS Code extensions, is designed to reduce boilerplate code, the amount of which is historically notorious in many Java projects. Lombok uses annotations for this task in order to streamline things like coding getters and setters. The dev team's Code Action tweak effectively enables developers to "Lombok" their code, Microsoft said, or "de-Lombok" the annotations they don't want by deselecting them.
The team also enhanced its code analysis capabilities by adding support for @Nullable and @Nonnull annotations. Those annotations inform the developer and compiler if it's okay to allow null for a variable, parameter or return value, Zhu said. Microsoft currently supports the @NonNull and @Nullable annotations from the following packages
"If we detect certain contracts are being violated, we will show the warnings in the problems section and also highlight them in the editor area," he said. His post includes a short demo of this feature in action.
Microsoft's Java on VS Code dev team is responsible for the Extension Pack for Java on Visual Studio Code in the editor's marketplace, which has enjoyed 15.5 million installs. Spring developers working on a Spring Boot application can also download the Spring Boot Extension Pack for "a specialized Spring experience."
David Ramel is an editor and writer for Converge360.