- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的网络应用程序在晚上运行作业!遇到问题!它占用了大量内存!
我用命令查找哪个函数占用了java资源!
结果是:
[tomcat@uhzd006525 ~]$ jstack 2365 |grep 93f -A 30
- parking to wait for <0x00000007eac93f68> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at org.apache.http.pool.PoolEntryFuture.await(PoolEntryFuture.java:131)
at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:281)
at org.apache.http.pool.AbstractConnPool.access$000(AbstractConnPool.java:62)
at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:176)
at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:172)
at org.apache.http.pool.PoolEntryFuture.get(PoolEntryFuture.java:100)
at org.apache.http.impl.conn.PoolingClientConnectionManager.leaseConnection(PoolingClientConnectionManager.java:212)
at org.apache.http.impl.conn.PoolingClientConnectionManager$1.getConnection(PoolingClientConnectionManager.java:199)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:456)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at com.trendata.spider.PageGetter.getPageContent(PageGetter.java:262)
at com.trendata.spider.PageGetter.getTaobaoContent(PageGetter.java:376)
at com.trendata.taobao.MbpBkDataCreator.getBkMbpValue(MbpBkDataCreator.java:48)
at com.trendata.taobao.MbpBkDataCreator.getIntoStores(MbpBkDataCreator.java:106)
at com.trendata.service.impl.OddJobsServiceImpl.getLast7DaysIntoStore(OddJobsServiceImpl.java:448)
at sun.reflect.GeneratedMethodAccessor205.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at com.trendata.service.interceptor.MethodCacheInterceptor.invoke(MethodCacheInterceptor.java:32)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy144.getLast7DaysIntoStore(Unknown Source)
at sun.reflect.GeneratedMethodAccessor205.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
--
"GC task thread#0 (ParallelGC)" prio=10 tid=0x0000000000d46000 nid=0x93f runnable
"GC task thread#1 (ParallelGC)" prio=10 tid=0x0000000000d48000 nid=0x940 runnable
"VM Periodic Task Thread" prio=10 tid=0x00002aaabc059800 nid=0x94b waiting on condition
JNI global references: 342
"Thread-114" prio=10 tid=0x000000002281e800 nid=0xf4a waiting on condition [0x000000004c7d3000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000790f5dc40> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
"Thread-113" prio=10 tid=0x0000000022624800 nid=0xf48 waiting on condition [0x000000004c6d2000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000790f5dc40> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
"Thread-112" prio=10 tid=0x00000000225d9800 nid=0xf37 waiting on condition [0x000000004c5d1000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000790f5dc40> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
--
"GC task thread#0 (ParallelGC)" prio=10 tid=0x000000001f287000 nid=0x7d30 runnable
"GC task thread#1 (ParallelGC)" prio=10 tid=0x000000001f288800 nid=0x7d31 runnable
"VM Periodic Task Thread" prio=10 tid=0x000000001f3d1000 nid=0x7d39 waiting on condition
JNI global references: 579
这是发生问题的代码:
public class PageGetter {
private static final Log log = LogFactory.getLog("serviceLogger");
private static SyncBasicHttpParams httpParams = null;
private HttpClient httpClient = null;
private static PoolingClientConnectionManager connectionManager = null;
private static Integer errorSleepTime = new Integer(PropertyGetter.getInstance().getProperty("errorpagesleeptime"));
public String getFinalRedirectURL(String url) throws ClientProtocolException, IOException {
if (url == null) {
return null;
}
if (!url.trim().startsWith("http://")) {
url = "http://" + url;
}
HttpContext localContext = new BasicHttpContext();
HttpGet httpget = new HttpGet(url);
if (connectionManager == null || httpParams == null || this.httpClient == null) {
this.initHttpManager();
}
this.httpClient.execute(httpget, localContext);
HttpHost target = (HttpHost) localContext.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
String finalURL = target.toString();
httpget.abort();
return finalURL;
}
private void initHttpManager() {
// Create and initialize HTTP parameters
if (httpParams == null) {
httpParams = new SyncBasicHttpParams();
httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000);
httpParams.setParameter(HTTP.CONTENT_ENCODING, "GBK");
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
}
if (connectionManager == null) {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
try {
//Security Socket
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
}
};
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
schemeRegistry.register(new Scheme("https", 443, ssf));
} catch (Exception e) {
log.error("Fail to create connection manager " + e);
}
connectionManager = new PoolingClientConnectionManager(schemeRegistry);
}
this.httpClient = new DefaultHttpClient(connectionManager, httpParams);
this.httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
HttpClientParams.setCookiePolicy(this.httpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY);
}
public String getPostPageContent(String url, List<NameValuePair> headers, List<NameValuePair> params) {
String strPage = null;
if (url == null) {
return null;
}
if (!url.trim().startsWith("http")) {
url = "http://" + url;
}
HttpPost httpPost = new HttpPost(url);
HttpEntity entity = null;
try {
if (params != null) {
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
}
if (headers != null) {
Iterator<NameValuePair> itrHeaders = headers.iterator();
while (itrHeaders.hasNext()) {
NameValuePair header = itrHeaders.next();
httpPost.setHeader(header.getName(), header.getValue());
}
}
HttpContext localContext = new BasicHttpContext();
if (connectionManager == null || httpParams == null || this.httpClient == null) {
this.initHttpManager();
}
HttpResponse response = this.httpClient.execute(httpPost, localContext);
// get the response body as an array of bytes
entity = response.getEntity();
if (entity != null) {
strPage = EntityUtils.toString(entity);
}
} catch (Exception e) {
connectionManager = null;
httpParams = null;
this.httpClient = null;
this.errorHandler(url, e);
} finally {
httpPost.abort();
if (entity != null) {
try {
EntityUtils.consume(entity);
} catch (Exception e2) {
e2.printStackTrace();
log.error("Error when consume entity ", e2);
}
}
}
if (strPage != null) {
Pattern pattern = Pattern.compile("\\s");
Matcher matcher = pattern.matcher(strPage);
strPage = matcher.replaceAll(" ");
strPage = strPage.replaceAll("////", "");
}
return strPage;
}
private String getURL(String url, List<NameValuePair> headers) {
if (headers == null) {
return url;
}
Map<String, String> map = new HashMap<String, String>();
if (url.contains("?")) {
String str = url.substring(url.indexOf("?") + 1);
url = url.substring(0, url.indexOf("?"));
String[] strs = str.split("&");
for (int i = 0; strs != null && i < strs.length; i++) {
if (strs[i].contains("=")) {
String key = strs[i].substring(0, strs[i].indexOf("="));
String value = strs[i].substring(strs[i].indexOf("=") + 1);
map.put(key, value);
}
}
}
Iterator<NameValuePair> itrHeaders = headers.iterator();
while (itrHeaders.hasNext()) {
NameValuePair header = itrHeaders.next();
if (header != null && header.getName() != null && header.getValue() != null) {
try {
map.put(URLEncoder.encode(header.getName(), "UTF-8"), URLEncoder.encode(header.getValue(), "UTF-8"));
} catch (Exception e) {
log.error("Can not parse parameter " + e);
}
}
}
if (map.keySet() == null) {
return url;
}
Iterator<String> itr = map.keySet().iterator();
String parameters = "";
while (itr.hasNext()) {
String key = itr.next();
if (key != null && key.length() > 0) {
parameters = parameters + key + "=" + map.get(key) + "&";
}
}
if (parameters.length() > 0) {
url = url + "?" + parameters;
}
return url;
}
private void errorHandler(String url, Exception e) {
try {
Thread.sleep(errorSleepTime);
log.error("无法打开链接" + url + " sleep " + errorSleepTime + e);
} catch (Exception e1) {
log.error("Error sleeping " + errorSleepTime + e1);
}
}
/**
* Get page as string from URL
*
* @param url
* @return
*/
public String getPageContent(String url, List<NameValuePair> headers) {
url = StringFilter.replaceUnicode(url);
String strPage = null;
if (url == null) {
return null;
}
if (!url.trim().startsWith("http")) {
url = "http://" + url;
}
if (url.endsWith("/")) {
url = url.substring(0, url.lastIndexOf("/"));
}
HttpGet httpGet = null;
HttpEntity entity = null;
try {
if (connectionManager == null || httpParams == null || this.httpClient == null) {
this.initHttpManager();
}
url = this.getURL(url, headers);
httpGet = new HttpGet(url);
HttpContext localContext = new BasicHttpContext();
HttpResponse response = this.httpClient.execute(httpGet, localContext);
entity = response.getEntity();
if (entity != null) {
String charSet = ContentType.getOrDefault(entity).getCharset().toString();
if (charSet == null) {
charSet = "UTF-8";
}
strPage = EntityUtils.toString(entity, charSet);
strPage = strPage.replaceAll("\r", "");
strPage = strPage.replaceAll("\n", "");
//空格
strPage = strPage.replaceAll(" ", "");
}
} catch (Exception e) {
connectionManager = null;
httpParams = null;
this.httpClient = null;
this.errorHandler(url, e);
} finally {
try {
httpGet.abort();
} catch (Exception e) {
log.error("Error when httpclient aborting " + e);
}
if (entity != null) {
try {
EntityUtils.consume(entity);
} catch (Exception e2) {
e2.printStackTrace();
log.error("Error when consume entity ", e2);
}
}
}
return strPage;
}
public String getPageContentSms(String url, List<NameValuePair> headers) {
url = StringFilter.replaceUnicode(url);
String strPage = null;
if (url == null) {
return null;
}
if (!url.trim().startsWith("http")) {
url = "http://" + url;
}
if (url.endsWith("/")) {
url = url.substring(0, url.lastIndexOf("/"));
}
HttpGet httpGet = null;
HttpEntity entity = null;
try {
if (connectionManager == null || httpParams == null || this.httpClient == null) {
this.initHttpManager();
}
httpGet = new HttpGet(url);
HttpContext localContext = new BasicHttpContext();
HttpResponse response = this.httpClient.execute(httpGet, localContext);
entity = response.getEntity();
if (entity != null) {
String charSet = ContentType.getOrDefault(entity).getCharset().toString();
if (charSet == null) {
charSet = "UTF-8";
}
strPage = EntityUtils.toString(entity, charSet);
strPage = strPage.replaceAll("\r", "");
strPage = strPage.replaceAll("\n", "");
strPage = strPage.replaceAll(" ", "");
}
} catch (Exception e) {
connectionManager = null;
httpParams = null;
this.httpClient = null;
this.errorHandler(url, e);
} finally {
try {
httpGet.abort();
} catch (Exception e) {
log.error("Error when httpclient aborting " + e);
}
if (entity != null) {
try {
EntityUtils.consume(entity);
} catch (Exception e2) {
e2.printStackTrace();
log.error("Error when consume entity ", e2);
}
}
}
return strPage;
}
public List<NameValuePair> getDefaultHeaders() {
List<NameValuePair> headers = new ArrayList<NameValuePair>();
BasicNameValuePair nameValuePair = new BasicNameValuePair("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
headers.add(nameValuePair);
nameValuePair = new BasicNameValuePair("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");
headers.add(nameValuePair);
nameValuePair = new BasicNameValuePair("Accept-Encoding", "GBK,utf-8;q=0.7,*;q=0.3");
headers.add(nameValuePair);
nameValuePair = new BasicNameValuePair("Accept-Language", "zh-CN,zh;q=0.8");
headers.add(nameValuePair);
nameValuePair = new BasicNameValuePair("Cache-Control", "max-age=0");
headers.add(nameValuePair);
nameValuePair = new BasicNameValuePair("Connection", "keep-alive");
headers.add(nameValuePair);
nameValuePair = new BasicNameValuePair("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19");
headers.add(nameValuePair);
return headers;
}
public String getTaobaoContent(List<NameValuePair> params) {
return this.getPageContent(Constant.TAOBAO_API_URL, params);
}
最佳答案
我们在将 HttpClient 与 Jersey 一起使用时遇到了非常相似的问题。线程被阻塞等待连接。
在我们的案例中,当我们在 GET 请求中遇到 40 次错误时连接池耗尽。
原因是连接永远不会释放回池中,除非我们真正读取响应主体(在我们收到客户端错误代码的情况下我们没有这样做)。在您的源代码中,您似乎只是在没有阅读响应的情况下抛出 ClientProtocolException。它可能是相似的。
关于java - 使用 Java Apache PoolingClientConnectionManager 泄漏内存,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21082692/
在流处理方面,Apache Beam和Apache Kafka之间有什么区别? 我也试图掌握技术和程序上的差异。 请通过您的经验报告来帮助我理解。 最佳答案 Beam是一种API,它以一种统一的方式使
有点n00b的问题。 如果我使用 Apache Ignite 进行消息传递和事件处理,是否还需要使用 Kafka? 与 Ignite 相比,Kafka 基本上会给我哪些(如果有的话)额外功能? 提前致
Apache MetaModel 是一个数据访问框架,它为发现、探索和查询不同类型的数据源提供了一个通用接口(interface)。 Apache Drill 是一种无架构的 SQL 查询引擎,它通过
Tomcat是一个广泛使用的java web服务器,而Apache也是一个web服务器,它们在实际项目使用中有什么不同? 经过一些研究,我有了一个简单的想法,比如, Apache Tomcat Ja
既然简单地使用 Apache 就足以运行许多 Web 应用程序,那么人们何时以及为什么除了 Apache 之外还使用 Tomcat? 最佳答案 Apache Tomcat是一个网络服务器和 Java
我在某个 VPS( friend 的带 cPanel 的 apache 服务器)上有一个帐户,我在那里有一个 public_html 目录。我们有大约 5-6 个网站: /home/myusernam
我目前正在尝试将模块加载到 Apache,使用 cmake 构建。该模块称为 mod_mapcache。它已成功构建并正确安装在/usr/lib/apache2/modules directroy 中
我对 url 中的问号有疑问。 例如:我有 url test.com/controller/action/part_1%3Fpart_2 (其中 %3F 是 url 编码的问号),并使用此重写规则:R
在同一台机器上,Apache 在端口 80 上运行,Tomcat 在端口 8080 上运行。 Apache 包括 html;css;js;文件并调用 tomcat 服务。 基本上 exampledom
Apache 1 和 Apache 2 的分支有什么区别? 使用一种或另一种的优点和缺点? 似乎 Apache 2 的缺点之一是使用大量内存,但也许它处理请求的速度更快? 最有趣的是 Apache 作
实际上,我们正在使用 Apache 网络服务器来托管我们的 REST-API。 脚本是用 Lua 编写的,并使用 mod-lua 映射。 例如来自 httpd.conf 的实际片段: [...] Lu
我在 apache 上的 ubuntu 中有一个虚拟主机,这不是我的主要配置,我有另一个网页作为我的主要网页,所以我想使用虚拟主机在同一个 IP 上设置这个。 urologyexpert.mx 是我的
我使用 Apache camel 已经很长时间了,发现它是满足各种系统集成相关业务需求的绝佳解决方案。但是几年前我遇到了 Apache Nifi 解决方案。经过一番谷歌搜索后,我发现虽然 Nifi 可
由于两者都是一次处理事件的流框架,这两种技术/流框架之间的核心架构差异是什么? 此外,在哪些特定用例中,一个比另一个更合适? 最佳答案 正如您所提到的,两者都是实时内存计算的流式平台。但是当您仔细观察
apache 文件(如 httpd.conf 和虚拟主机)中使用的语言名称是什么,例如 # Ensure that Apache listens on port 80 Listen 80 D
作为我学习过程的一部分,我认为如果我扩展更多关于 apache 的知识会很好。我有几个问题,虽然我知道有些内容可能需要相当冗长的解释,但我希望您能提供一个概述,以便我知道去哪里寻找。 (最好引用 mo
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4 个月前关闭。 Improve
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
这个问题在这里已经有了答案: Difference Between Apache Kafka and Camel (Broker vs Integration) (4 个回答) 3年前关闭。 据我所知
我有 2 个使用相同规则的子域,如下所示: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond
我是一名优秀的程序员,十分优秀!