当前位置:七道奇文章资讯数据防范Oracle防范
日期:2011-01-25 22:55:00  来源:本站整理

简单办理复杂的Oracle IAS问题-性能调优[Oracle防范]

赞助商链接



  本文“简单办理复杂的Oracle IAS问题-性能调优[Oracle防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

    笔者做了一个小的系统帮助功效,可以周期性拜候某个URL、履行某个SQL语句 or 履行某个系统号令.

    履行SQL语句和系统号令对比简单,这里不再详述,主要说一下拜候某个URL.

    实际上JDK自身已有工具类用于成立HTTP恳求,类名是:java.net.HttpURLConnection,但考虑到底子类普通对比粗糙,很多情形要自己考虑和处理,就回头去Google了下,发现公然有开源的工具包可以利用,几个工具包中以HttpClient较为常用,并且是apache的东东,于是决意采取HttpClient.

    从apache上down了包commons-httpclient-3.1.jar和commons-codec-1.3.jar两个包,后者是HttpClient依靠的包.

    帮忙写的很好,即就是像我这样英文很烂,也能很快上手.

public boolean visitURL(String url) {

// Commons HttpClient 3.1
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);

// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));

boolean rs = false;

try {

// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
logger.error("Method failed: " + method.getStatusLine());
}
else {
rs = true;   
}

} catch (HttpException e) {
logger.error("Fatal protocol violation: " + e.getMessage());
} catch (IOException e) {
logger.error("Fatal transport error: " + e.getMessage());
} finally {
// Release the connection.
method.releaseConnection();
}

return rs;
}

    本机Tomcat下run一下,工作正常,随即丢到服务器Oracle IAS环境)上测试,程序应当出其不意的报了个错.

09/03/16 19:03:43 java.lang.NoClassDefFoundError
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodBase.writeRequestLine(HttpMethodBase.java:2015)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:1864)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:975)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:368)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:164)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:437)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
09/03/16 19:03:43 at com.zbht.util.TimerTaskManager.runURLTask(TimerTaskManager.java:237)
09/03/16 19:03:43 at _system._timer__task._test._jspService(_test.java:182)
09/03/16 19:03:43 at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
09/03/16 19:03:43 at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
09/03/16 19:03:43 at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
09/03/16 19:03:43 at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
09/03/16 19:03:43 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
09/03/16 19:03:43 at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
09/03/16 19:03:43 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
09/03/16 19:03:43 at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
09/03/16 19:03:43 at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
09/03/16 19:03:43 at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:302)
09/03/16 19:03:43 at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:190)
09/03/16 19:03:43 at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
09/03/16 19:03:43 at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
09/03/16 19:03:43 at java.lang.Thread.run(Thread.java:595)

    错误信息看上去对比初级:NoClassDefFoundError,类没找到,疾速了查抄了一下本机和服务器上的jar包能否相同,"一模一样"!这就奇特了.

    查抄本机的开辟环境,只增添了这两个jar,其他的都没有动过,又查抄服务器的运行环境,一样没有改变.于是删掉本机开辟环境下的这两个jar,问题浮出来了,类中对httpclient的7、8个引用中只有1个提醒未找到指定的类,看来Oracle自己的某个包中已经包含某个较低版本的httpclient,jar包冲突的问题是件让人懊丧的事情,尝试办理这种问题会所耗费的时间大概是其他办法的N倍,无心恋战.

    其实此处要举行的操作很简单,就是拜候指定的URL,按照返回的内容查抄能否成功,HttpClient是完好模拟浏览器,考虑了很多种问题,利用起来反倒是复杂了,决意转用JDK的底子类:java.net.HttpURLConnection

    事情出奇的顺利,空间里找到了之前写的一个办法,恰好办理这个问题,以下是代码清单:

  以上是“简单办理复杂的Oracle IAS问题-性能调优[Oracle防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • Linux Nginx VPS下简单办理CC攻击
  • 简单办理复杂的Oracle IAS问题-性能调优
  • 简单办理mysql占用资源过大的问题
  • private boolean visitURL(String strUrl, String successFlag) {

    boolean rs = false;
    HttpURLConnection jconn = null;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    try {
    URL url = new URL(strUrl);

    jconn = (HttpURLConnection) url.openConnection();
    jconn.setDoOutput(true);
    jconn.setDoInput(true);
    jconn.connect();

    InputStream in = jconn.getInputStream();
    byte[] buf = new byte[4096];

    int bytesRead;
    while ((bytesRead = in.read(buf)) != -1) {
    byteArrayOutputStream.write(buf, 0, bytesRead);
    }

    String strRead = new String(byteArrayOutputStream.toByteArray());

    logger.debug(strRead);

    strRead = StringUtil.NVL(strRead);

    if(strRead.indexOf(successFlag) != -1) {
    logger.info("Visit URL < " + strUrl + " > success !");
    rs = true;
    }

    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    jconn.disconnect();

    try {
    byteArrayOutputStream.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }

    return rs;
    }

    本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .