目前我正在使用Java代理来组装内存统计信息.在instrumentation API的帮助下,我可以获得类(并操纵它们).使用普通Java,我可以估计每个对象使用的资源.到现在为止还挺好.
我现在面临的问题是"如何掌握特定类的每个Object实例".我可以进行字节代码操作以获取对象实例,但我希望有另一个我不知道的API,帮助我实现我的目标,没有这么大的侵入性步骤.最后,应将性能影响保持在最低限度.有任何想法吗?
我实际上正在使用架构第一种方法,但是我遇到了"不祥的" JAXB Map问题的障碍!并通过切换到这个代码的第一种方法来解决它.现在,我想在其他模块中重用此类型,并通过从生成的模式创建一个剧集文件来继续我的模式第一种方法.不幸的是,生成的剧集文件是空的.这是我尝试过的:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>schemagen</id>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<generateEpisode>true</generateEpisode>
<transformSchemas>
<transformSchema>
<uri>http://some/schema/types</uri>
<toPrefix>core</toPrefix>
<toFile>core-types.xsd</toFile>
</transformSchema>
</transformSchemas>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这为我生成了以下架构:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:core="http://some/schema/types" targetNamespace="http://some/schema/types" version="1.0">
<xs:element name="Map" type="core:MapType"/>
<xs:complexType name="MapType">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="entries" nillable="true" type="core:EntryType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="EntryType">
<xs:sequence>
<xs:element name="key" type="xs:anyType"/>
<xs:element name="value" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
以及包含此内容的剧集文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:bindings version="2.1" xmlns:ns1="http://java.sun.com/xml/ns/jaxb"/>
Run Code Online (Sandbox Code Playgroud)
我尝试使用schemagen standalone(版本2.2.11),结果类似.https://jaxb.java.net/2.2.4/docs/schemagen.html和http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/schemagen-mojo.html上的文档接缝表明这应该是它,但我无法弄清楚我做错了什么.