Old JaxB and JDK8 Metaspace OutOfMemory Issue

前端 未结 3 509
陌清茗
陌清茗 2020-12-02 20:56

We are working on a business application (1 million+ LOC) developed since 10+ years. While switching to JDK8 we get an issue with the metaspace of JDK8. This seems to be rel

相关标签:
3条回答
  • 2020-12-02 21:19

    Here is the solution Gary is talking about, which is better than just setting a flag (since even the JAXB guys suggest to make it singleton...)

    private static Map<class<?>, JAXBContext> contextStore = new ConcurrentHashMap<class<?>, JAXBContext>();
    ... 
    protected static JAXBContext getContextInstance(Class<?> objectClass) throws JAXBException{
      JAXBContext context = contextStore.get(objectClass);
      if (context==null){
        context = JAXBContext.newInstance(objectClass);
        contextStore.put(objectClass, context);
      }
      return context;
    }
    
    //using it like this:
    JAXBContext context = getContextInstance(objectClass);
    
    0 讨论(0)
  • 2020-12-02 21:22

    JAXBContext.newInstance() should be used once to create a context for your class to unmarshall. It will use up your permgen or metaspace otherwise.

    0 讨论(0)
  • 2020-12-02 21:31

    We solved our current issue untill able to fix all occurances in our application by using the following VM-parameter:

    -Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true
    

    I hope this will help others with similar issues...

    0 讨论(0)
提交回复
热议问题