Home > front end >  Thread Context is a internal proprietary api and may be removed in future
Thread Context is a internal proprietary api and may be removed in future

Time:01-18

I am using com.sun.jmx.snmp.ThreadContext class to push some variable value in one java class by using ThreadContext.push("variable",value) and in other class retriving it by ThreadContext.get(variablename), But it is giving me compilation error when "mvn clean install". telling "Thread Context is a internal proprietary api and may be removed in future" However if I am running clean install from intelljidea then giving "build success"

Please suggest me what to use to replace ThreadContext with same feature.

Thanks.

CodePudding user response:

You can try MDC, docs

MDC.put("userName", "test");

CodePudding user response:

It is a warning, but it is not one that you should ignore. The com.sun.jmx.snmp.ThreadContext class has been removed in Java 9 and later.

There is no direct replacement for this class in Java 9 and later. Indeed, the entire com.sun.jmx.snmp package tree has been removed from Java SE; see https://bugs.openjdk.org/browse/JDK-8060692

However, based on how ThreadContext seems to work, you should be able to replace this functionality by using ThreadLocal (javadoc).

Alternatively, you could also simply copy the source code of the OpenJDK ThreadContext class, change its package name and add it to your own codebase. However the OpenJDK codebase is covered by the GPLv2 copyleft license ... and you MUST read, understand and respect the terms of the license ... even if you just copy only one class.

  •  Tags:  
  • java
  • Related