---
title: "jdk设置java.net.useSystemProxies后没有关闭句柄的bug?"
author: "herry"
date: "2013-03-28T17:31:10Z"
tags: []
categories: ["企业架构"]
slug: "jdk-java-net-usesystemproxies-bug"
draft: false
lastmod: "2013-03-29T08:50:16Z"
id: 1838156
url: "https://herry.iteye.com/blog/1838156"
---

jdk的bug?
当设置如下参数时:

```java
 
try {
   System.setProperty("java.net.useSystemProxies","true");
} catch (SecurityException e) {
    ; // failing to set this property isn't fatal
}
```

在windows中看到进程的句柄数一直在增加。而去掉该参数的设置之后句柄就正常
通过[Handle Tracer](http://www.novirusthanks.org/products/license/freeware/)可以看到有很多句柄引用的ObjectName如下:
HKEY_USERS\S-1-5-21-1409082233-1637723038-725345543-1003\Software\Microsoft\Windows\CurrentVersion\Internet Settings
![](http://dl.iteye.com/upload/attachment/0082/3534/ce9d5bbd-7fe0-39b1-9dbf-b392335cbae1.jpg)
通过ProcessMonitor进一步查看注册表相关的动作,可以看到如下的截图:
![](http://dl.iteye.com/upload/attachment/0082/3538/8de4b109-810f-3f59-96e7-4db85e903672.jpg)
而正常的应该是:
![](http://dl.iteye.com/upload/attachment/0082/3536/d3270e11-2191-3041-bed2-274815f6a949.jpg)
非正常的打开注册表之后一直没有关闭注册表，只要访问网络都会导致句柄(handler)数一直增加。