With Java 19, VS Code Now Does Virtual Threads While Debugging

The latest update to Java on Visual Studio Code improves the debugging experience thanks to support for the newly released Java 19.

Java 19 shipped a month ago with a preview of Virtual Threads and Structured Concurrency thanks to Project Loom, the backing tech responsible for one of many debugging improvements in the October 2022 update. 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 sports 15.5 million installs.

"Java 19 brings the first preview of virtual threads to the Java platform; This is the primary deliverable of Project Loom," Microsoft said in an Oct. 21 blog post. "Virtual threads are designed to significantly boost the scalability of concurrent Java programming while making little change to the current API. 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."

Virtual Threads
[Click on image for larger view.] Virtual Threads (source: Microsoft).

More about this feature is available in Oracle's Java Magazine article, "Coming to Java 19: Virtual threads and platform threads."

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 like this:

Stream.of("Frank").map(name -> name.toUpperCase()).forEach((item -> System.out.println(item));

"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," Microsoft said. "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."

That new functionality is demonstrated in this animated GIF:

Inline Breakpoints in Animated Action
[Click on image for larger, animated GIF view.] Inline Breakpoints in Animated Action (source: Microsoft).

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 "DeLombok" the annotations they don't want anymore by deselecting them.

And, speaking of annotations, in yet another improvement the team 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, Microsoft said.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


  • Creating Reactive Applications in .NET

    In modern applications, data is being retrieved in asynchronous, real-time streams, as traditional pull requests where the clients asks for data from the server are becoming a thing of the past.

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

Subscribe on YouTube