我试图了解如何在本机代码中处理套接字读取超时,并发现一些奇怪的硬编码值,即5000毫秒:
if (timeout) {
if (timeout <= 5000 || !isRcvTimeoutSupported) {
int ret = NET_Timeout (fd, timeout);
.....
.....
}
}
Run Code Online (Sandbox Code Playgroud)
来源:http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/windows/native/java/net/SocketInputStream.c
我可以看到,变量isRcvTimeoutSupported通常设置为true,但在设置套接字选项时可能会被删除为false:
/*
* SO_RCVTIMEO is only supported on Microsoft's implementation
* of Windows Sockets so if WSAENOPROTOOPT returned then
* reset flag and timeout will be implemented using
* select() -- see SocketInputStream.socketRead.
*/
if (isRcvTimeoutSupported) {
jclass iCls = (*env)->FindClass(env, "java/lang/Integer");
jfieldID i_valueID;
jint timeout;
CHECK_NULL(iCls);
i_valueID = (*env)->GetFieldID(env, iCls, "value", "I");
CHECK_NULL(i_valueID);
timeout …
Run Code Online (Sandbox Code Playgroud) 我需要从jar加载XSD文件,所以实现了LSResourceResolver,如下所示:
Source schemaFile = new StreamSource(getClass().getClassLoader().getResourceAsStream("resources/xsd/root/maindoc/MainSchema.xsd"));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver(){
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
LSInput input = new DOMInputImpl();
String filePath = getNormalizedPath("resources/xsd/root/maindoc/", systemId);
InputStream stream = getClass().getClassLoader().getResourceAsStream(filePath);
input.setPublicId(publicId);
input.setSystemId(systemId);
input.setBaseURI(baseURI);
input.setCharacterStream(new InputStreamReader(stream));
return input;
}
});
Schema schema = schemaFactory.newSchema(schemaFile);
Run Code Online (Sandbox Code Playgroud)
此类实现成功解析了主模式中的链接,但无法解析引用文档中的链接.
通过引用文档的调用,我收到的不是null的baseURI参数,但是在我的情况下它的值就像是"file:///var/xxx/yyy.xsd",所以看起来不可能从这个构造一个有效的路径的systenId.
我错过了什么吗?是否可以递归地使解析器工作?
当然有一种解决方法可以展平架构,但我不太喜欢它.
注意到生产服务器(Websphere8.5.5)开始消耗大量内存.
javacore转储中的数字清楚地表明罪魁祸首是一堆杂乱无章的堆:
| +--Memory Manager (GC): 5,496,900,272 bytes / 3193 allocations
| | |
| | +--Java Heap: 5,368,770,560 bytes / 1 allocation
| | |
| | +--Other: 128,129,712 bytes / 3192 allocations
Run Code Online (Sandbox Code Playgroud)
但与此同时,在MAT中打开的堆转储报告堆的总容量大约为200M(有时高达300M,但从不多).
它到底意味着什么?堆转储是否值得信赖?如果是,是否有办法释放未使用的堆内存?
更新:完整的NATIVEMEM部分,根据要求
1MEMUSER JRE: 7,211,791,256 bytes / 39196 allocations
1MEMUSER |
2MEMUSER +--VM: 6,772,051,048 bytes / 29934 allocations
2MEMUSER | |
3MEMUSER | +--Classes: 370,339,176 bytes / 10002 allocations
3MEMUSER | | |
4MEMUSER | | +--Shared Class Cache: 62,914,560 bytes / 1 allocation
3MEMUSER …
Run Code Online (Sandbox Code Playgroud)