search
HomeTechnology peripheralsAIStop messing around, these features will be deprecated and removed in Java 21!

Although Java is one of the most backwards compatible languages ​​and environments I have ever used, there is always the possibility of functionality being deprecated or even removed. Java 21 will deprecate two features, and that’s what we’re going to talk about today.

1 Why should functionality be deprecated?

Deprecating code or functionality means that its use is discouraged and may no longer exist in a future version. There may be many reasons why it is not encouraged.

The most common reasons for deprecation are:

  • It has been superseded by a better alternative.
  • It has design flaws and may even be dangerous to use. But due to backward compatibility, it cannot be removed immediately, or at all.
  • It is considered redundant and should be removed to simplify the system and how it is used.
  • Future updates will make it impossible/impractical to support old functionality/code.

Regardless of the root cause, the deprecated functionality is still part of the system and therefore is still available, at least for now.

Deprecating Windows 32-bit x86 port

JEP449 aims to deprecate 32-bit x86 support for Windows, with the ultimate goal of removing it entirely in the future.

The reasons behind this deprecation and its future removal are primarily technical.

Windows 32-bit Support

Providing software for any system always requires deciding which platforms you actually want to support. Targeting platforms or versions that are no longer supported is possible, but usually means increasing support efforts, backporting, fixing things yourself, etc.

Taking the Windows platform as an example, the last 32-bit version was released in 2020, and official support ended in October 2025.

If you know how 64-bit Windows handles 32-bit applications, you may be wondering why you can't run the JVM through Windows' integrated WOW64 emulation layer? Well, it's usually possible to run applications this way, but performance will drop dramatically.

This is why the OpenJDK team decided to move forward with the deprecation, as it only affects future versions of Java. Older systems will still be able to use all Java versions prior to removal.

One of the direct changes in Java 21 affects the build process of the JDK, as the possibility to configure the build is disabled by default. Trying to run bash ./configure gives the error:

...checking compilation type... nativeconfigure: error: The Windows 32-bit x86 port is deprecated and may be removed in a future release. \Use --enable-deprecated-ports=yes to suppress this error.configure exiting with result code 1

Since the feature was simply deprecated, not removed, the OpenJDK team added a new configuration option (as shown in the error ), --enable-deprecated-ports=yes to still allow configuration. However, a warning will be issued to highlight deprecation and possible future removal.

$ bash ./configure --enable-deprecated-ports=yes...checking compilation type... nativeconfigure: WARNING: The Windows 32-bit x86 port is deprecated and may be removed in a future release....Build performance summary:* Cores to use: 32* Memory limit: 96601 MBThe following warnings were produced. Repeated here for convenience:WARNING: The Windows 32-bit x86 port is deprecated and may be removed in a future release.

Virtual VS Kernel Threads

Java 21 is full of awesome new features, and the addition of virtual threads (JEP 444) is one of them. It introduces lightweight (virtual) threads, which may significantly change the way we handle high-throughput concurrent applications in Java by reducing the effort required to write, maintain, and observe such applications. They have much less overhead than traditional platform (kernel) threads

However, on Windows 32-bit x86, due to technical limitations, this functionality must fall back to kernel threads. This missing functionality of the underlying platform is often a strong indicator of future deprecation and removal.

Still, you can write and use new threading code, but in practice it lacks the expected benefits.

Deprecated, but not yet removed

As you can see, the deprecation makes sense, since Windows 32-bit x86 won't run anyway. Additionally, building for specific platforms is still possible, it's just discouraged at this time. So if you still need to support legacy systems and know what you're doing and what the consequences are, you can still use it.

Disable dynamic loading of agents

The agent uses the Instrumentation API to modify existing applications by changing the bytecode that has been loaded in the JVM. This enables you to change the behavior of your application without actually changing its source code. It is commonly used in profilers and monitoring tools (such as Datadog and YourKit), aspect-oriented programming, and more.

How to load the agent

There are two ways to load the agent, one is to load it statically by adding parameters or calling, and the other is to run the following code from Another application is dynamically loaded: -javaagent:agent-to-load.jar-agentlib:optionsjava

import java.lang.management.ManagementFactory;import com.sun.tools.attach.VirtualMachine;public class DynamicAgentLoader {public static void main(String... args) {int pidOfOtherJVM = ...;File agentJar = ...;try {VirtualMachine vm = VirtualMachine.attach(pidOfOtherJVM);vm.loadAgent(agentJar.toAbsolutePath);// ... do your workvm.detach();} catch (Exception e) {// ...}}}

The first option is not a big problem. This is a clear and intentional use of the JVM agent. However, the latter is indirect and may not be controlled by the connected JVM.

动态加载的问题

Java 平台默认致力于实现完整性,为我们构建应用程序提供强大而坚实的基础。代理的设计考虑到了最好的意图,为您提供(良性)工具的力量。然而,为了确保这种完整性,通过(动态)代理进行检测是一个大问题,因为它们超出了您的直接控制范围,并且可能会对您的应用程序造成严重破坏。这就是为什么您作为应用程序的所有者必须对允许和加载哪些代理做出有意识且明确的决定。

插播一条,如果你近期准备面试跳槽,建议在ddkk.com在线刷题,涵盖 1万+ 道 Java 面试题,几乎覆盖了所有主流技术面试题,还有市面上最全的技术栈500套,精品系列教程,免费提供。

在Java 21 中,您仍然可以加载动态代理,但 JVM 会生成多个警告,通知您潜在的问题以及如何隐藏这些警告:

WARNING: A {Java,JVM TI} agent has been loaded dynamically (file:/path/to/agent.jar)WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warningWARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more informationWARNING: Dynamic loading of agents will be disallowed by default in a future release

未来的Java 版本将默认禁止加载动态代理,并且任何使用Attach API都会引发异常:

com.sun.tools.attach.AgentLoadException: Failed to load agent library: \Dynamic agent loading is not enabled. Use -XX:+EnableDynamicAgentLoading \to launch target VM.

异常消息包括启用动态代理加载所需的步骤:参数-XX:+EnableDynamicAgentLoading。因此,如果您有意识地决定允许动态代理,那么您仍然可以。

立即禁用动态加载

到目前为止,仅发出警告。但是,您可以完全禁止动态加载 Java 代理。您可以通过使用将(加号)与(破折号/减号)-XX:-EnableDynamicAgentLoading交换的参数来执行此操作,以强化您的应用程序或为即将到来的更改做好准备。+-

2 结论

本文中提到的两个功能的弃用对我来说是有道理的。

Windows 10 32 位 x86 支持是一项技术债务,阻碍了创新,例如利用虚拟线程的全部功能。

动态加载代理严重损害了 Java 平台的完整性,并且存在潜在的安全风险。如果打击者“足够接近”可以连接到另一个 JVM,那么您可能会遇到更大的问题。

尽管如此,我们始终必须意识到将来可能会发生变化或删除的内容,因为我们很可能无法决定它何时发生。Java 通常对弃用和删除时间框架相当慷慨,某些功能可能会弃用数十年,但看不到删除的迹象。所以很自然地,我们是否应该使用已弃用的 API 的问题就出现了。

在我看来,如果可能的话,我们应该尽量避免使用已弃用的 API。随着时间的推移,它正在成为技术债务,最终必须偿还。没有什么比因为不相关的原因而需要升级代码更有压力的了,而且您多年来依赖的一些已弃用的功能最终被删除,使得升级方式比需要的更加复杂。

The above is the detailed content of Stop messing around, these features will be deprecated and removed in Java 21!. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
How to Build Your Personal AI Assistant with Huggingface SmolLMHow to Build Your Personal AI Assistant with Huggingface SmolLMApr 18, 2025 am 11:52 AM

Harness the Power of On-Device AI: Building a Personal Chatbot CLI In the recent past, the concept of a personal AI assistant seemed like science fiction. Imagine Alex, a tech enthusiast, dreaming of a smart, local AI companion—one that doesn't rely

AI For Mental Health Gets Attentively Analyzed Via Exciting New Initiative At Stanford UniversityAI For Mental Health Gets Attentively Analyzed Via Exciting New Initiative At Stanford UniversityApr 18, 2025 am 11:49 AM

Their inaugural launch of AI4MH took place on April 15, 2025, and luminary Dr. Tom Insel, M.D., famed psychiatrist and neuroscientist, served as the kick-off speaker. Dr. Insel is renowned for his outstanding work in mental health research and techno

The 2025 WNBA Draft Class Enters A League Growing And Fighting Online HarassmentThe 2025 WNBA Draft Class Enters A League Growing And Fighting Online HarassmentApr 18, 2025 am 11:44 AM

"We want to ensure that the WNBA remains a space where everyone, players, fans and corporate partners, feel safe, valued and empowered," Engelbert stated, addressing what has become one of women's sports' most damaging challenges. The anno

Comprehensive Guide to Python Built-in Data Structures - Analytics VidhyaComprehensive Guide to Python Built-in Data Structures - Analytics VidhyaApr 18, 2025 am 11:43 AM

Introduction Python excels as a programming language, particularly in data science and generative AI. Efficient data manipulation (storage, management, and access) is crucial when dealing with large datasets. We've previously covered numbers and st

First Impressions From OpenAI's New Models Compared To AlternativesFirst Impressions From OpenAI's New Models Compared To AlternativesApr 18, 2025 am 11:41 AM

Before diving in, an important caveat: AI performance is non-deterministic and highly use-case specific. In simpler terms, Your Mileage May Vary. Don't take this (or any other) article as the final word—instead, test these models on your own scenario

AI Portfolio | How to Build a Portfolio for an AI Career?AI Portfolio | How to Build a Portfolio for an AI Career?Apr 18, 2025 am 11:40 AM

Building a Standout AI/ML Portfolio: A Guide for Beginners and Professionals Creating a compelling portfolio is crucial for securing roles in artificial intelligence (AI) and machine learning (ML). This guide provides advice for building a portfolio

What Agentic AI Could Mean For Security OperationsWhat Agentic AI Could Mean For Security OperationsApr 18, 2025 am 11:36 AM

The result? Burnout, inefficiency, and a widening gap between detection and action. None of this should come as a shock to anyone who works in cybersecurity. The promise of agentic AI has emerged as a potential turning point, though. This new class

Google Versus OpenAI: The AI Fight For StudentsGoogle Versus OpenAI: The AI Fight For StudentsApr 18, 2025 am 11:31 AM

Immediate Impact versus Long-Term Partnership? Two weeks ago OpenAI stepped forward with a powerful short-term offer, granting U.S. and Canadian college students free access to ChatGPT Plus through the end of May 2025. This tool includes GPT‑4o, an a

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor