java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE 的理解

[2013-12-06 11:06:21,715] [C3P0PooledConnectionPoolManager[identityToken->2tl0n98y1iwg7cbdzzq7a|719f1f]-HelperThread-#2] DEBUG - com.mchange.v2.c3p0.impl.NewPooledConnection@484c6b closed by a client.
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:646)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:259)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:619)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:1024)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)
[2013-12-06 11:06:21,716] [C3P0PooledConnectionPoolManager[identityToken->2tl0n98y1iwg7cbdzzq7a|719f1f]-HelperThread-#2] DEBUG - Successfully destroyed PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@484c6b

经过分析源码,得到的结论是这个异常可以无视掉。
相关源码如下(c3p0版本:c3p0-0.9.2.1):
package com.mchange.v2.c3p0.impl;

import java.util.*;
import java.sql.*;
import javax.sql.*;
import com.mchange.v2.c3p0.*;
import com.mchange.v2.c3p0.stmt.*;
import com.mchange.v2.c3p0.util.*;
import com.mchange.v2.log.*;

import java.lang.reflect.Method;
import com.mchange.v2.lang.ObjectUtils;
import com.mchange.v2.sql.SqlUtils;

public final class NewPooledConnection extends AbstractC3P0PooledConnection{

    private final static MLogger logger = MLog.getLogger( NewPooledConnection.class );
//  methods below must be called from sync'ed methods

    /*
     *  If a throwable cause is provided, the PooledConnection is known to be broken (cause is an invalidating exception)
     *  and this method will not throw any exceptions, even if some resource closes fail.
     *
     *  
     *  if resources unexpectedlay fail to close.
     */
    private void close( Throwable cause ) throws SQLException
    { close( cause, false ); }

    private void close( Throwable cause, boolean forced ) throws SQLException
    {
    assert Thread.holdsLock( this );

        if ( this.invalidatingException == null )
        {
            List closeExceptions = new LinkedList();

            // cleanup ResultSets
            cleanupResultSets( closeExceptions );

            // cleanup uncached Statements
        // System.err.println(this + ".close( ... ) -- uncachedActiveStatements: " + uncachedActiveStatements);
            cleanupUncachedStatements( closeExceptions );

            // cleanup cached Statements
            try
            { closeAllCachedStatements(); }
            catch ( SQLException e )
            { closeExceptions.add(e); }

        if ( forced )
        {
            // reset transaction state
            try { C3P0ImplUtils.resetTxnState( physicalConnection, forceIgnoreUnresolvedTransactions, autoCommitOnClose, false ); }
            catch (Exception e)
            {
                if (logger.isLoggable( MLevel.FINER ))
                logger.log( MLevel.FINER,
                        "Failed to reset the transaction state of  " + physicalConnection + "just prior to close(). " +
                        "Only relevant at all if this was a Connection being forced close()ed midtransaction.",
                        e );
            }
        }

            // cleanup physicalConnection
            try
            { physicalConnection.close(); }
            catch ( SQLException e )
            {
                if (logger.isLoggable( MLevel.FINER ))
                    logger.log( MLevel.FINER, "Failed to close physical Connection: " + physicalConnection, e );

                closeExceptions.add(e);
            }

            // update our state to bad status and closed, and log any exceptions
            if ( connection_status == ConnectionTester.CONNECTION_IS_OKAY )
                connection_status = ConnectionTester.CONNECTION_IS_INVALID;
            if ( cause == null )
            {
                this.invalidatingException = NORMAL_CLOSE_PLACEHOLDER;

                if ( Debug.DEBUG && logger.isLoggable( MLevel.FINEST ) )
                    num:646 in the NewPooledConnection.java
/*                

Note that:
1、This is not an exception, the new Exception is used merely to show execution path for debug purposes.
2、And yes, this is only a debug message (actually, FINEST is the lowest possible level in java.util.logging).
To wrap this up: ignore and tune your logging levels to skip these.

http://stackoverflow.com/questions/8403227/weird-error-close-by-client-stack-trace

既然成功了,干嘛还要丢异常出来?

这里就不得不说到两个商业开发的原则问题了。
第一,对上家传入数据严加过滤,对传出给下家的数据仔细检查。
第二,合理使用异常。
第一点其实很简单的。也就是模块化开发的一个思想问题。对自己的行为负责。前端返回的数据究竟是什么,需要进行校验。不合格的剔除或者是修正。合格的处理完后,在传出之前也要加以校验,是否合格

结合到 “合理使用异常” 这句话来说呢,就是说,需要抛出异常的时候,就抛出。不需要抛出的时候,就不抛出。对程序员来说,在必要的时候看到一串异常信息,是最合适的事情了。

http://www.zhixing123.cn/jsp/23305.html

 

*/

                 logCloseExceptions( null, closeExceptions );

                if (closeExceptions.size() > 0)
                    throw new SQLException("Some resources failed to close properly while closing " + this);
            }
            else
            {
                this.invalidatingException = cause;
                if (Debug.TRACE >= Debug.TRACE_MED)
                    logCloseExceptions( cause, closeExceptions );
                else
                    logCloseExceptions( cause, null );
            }
        }
    }
 
/********************************************************************
 * This class generated by com.mchange.v2.debug.DebugGen
 * and will probably be overwritten by the same! Edit at
 * YOUR PERIL!!! Hahahahaha.
 ********************************************************************/

package com.mchange.v2.c3p0.impl;

import com.mchange.v2.debug.DebugConstants;

final class Debug implements DebugConstants
{
    
    final static int     TRACE = TRACE_MAX;

    private Debug()
    {}
}
 
package com.mchange.v2.log;

import java.util.*;

public final class MLevel
{
    public final static MLevel ALL;
    public final static MLevel CONFIG;
    public final static MLevel FINE;
    public final static MLevel FINER;
    public final static MLevel FINEST;
    public final static MLevel INFO;
    public final static MLevel OFF;
    public final static MLevel SEVERE;
    public final static MLevel WARNING;

    private final static Map integersToMLevels;
    private final static Map namesToMLevels;

    public static MLevel fromIntValue(int intval)
    { return (MLevel) integersToMLevels.get( new Integer( intval ) ); }

    public static MLevel fromSeverity(String name)
    { return (MLevel) namesToMLevels.get( name ); }

    static
    {
    Class lvlClass;
    boolean jdk14api;  //not just jdk14 -- it is possible for the api to be present with older vms
    try
        {
        lvlClass = Class.forName( "java.util.logging.Level" );
        jdk14api = true;
        }
    catch (ClassNotFoundException e )
        {
        lvlClass = null;
        jdk14api = false;
        }

    MLevel all;
    MLevel config;
    MLevel fine;
    MLevel finer;
    MLevel finest;
    MLevel info;
    MLevel off;
    MLevel severe;
    MLevel warning;

    try
        {
        // numeric values match the intvalues from java.util.logging.Level
        all = new MLevel( (jdk14api ? lvlClass.getField("ALL").get(null) : null), Integer.MIN_VALUE, "ALL" );
        config = new MLevel( (jdk14api ? lvlClass.getField("CONFIG").get(null) : null), 700, "CONFIG" );
        fine = new MLevel( (jdk14api ? lvlClass.getField("FINE").get(null) : null), 500, "FINE" );
        finer = new MLevel( (jdk14api ? lvlClass.getField("FINER").get(null) : null), 400, "FINER" );
        finest = new MLevel( (jdk14api ? lvlClass.getField("FINEST").get(null) : null), 300, "FINEST" );
        info = new MLevel( (jdk14api ? lvlClass.getField("INFO").get(null) : null), 800, "INFO" );
        off = new MLevel( (jdk14api ? lvlClass.getField("OFF").get(null) : null), Integer.MAX_VALUE, "OFF" );
        severe = new MLevel( (jdk14api ? lvlClass.getField("SEVERE").get(null) : null), 900, "SEVERE" );
        warning = new MLevel( (jdk14api ? lvlClass.getField("WARNING").get(null) : null), 1000, "WARNING" );
        }
    catch ( Exception e )
        {
        e.printStackTrace();
        throw new InternalError("Huh? java.util.logging.Level is here, but not its expected public fields?");
        }

    ALL = all;
    CONFIG = config;
    FINE = fine;
    FINER = finer;
    FINEST = finest;
    INFO = info;
    OFF = off;
    SEVERE = severe;
    WARNING = warning;

    Map tmp = new HashMap();
    tmp.put( new Integer(all.intValue()), all);
    tmp.put( new Integer(config.intValue()), config);
    tmp.put( new Integer(fine.intValue()), fine);
    tmp.put( new Integer(finer.intValue()), finer);
    tmp.put( new Integer(finest.intValue()), finest);
    tmp.put( new Integer(info.intValue()), info);
    tmp.put( new Integer(off.intValue()), off);
    tmp.put( new Integer(severe.intValue()), severe);
    tmp.put( new Integer(warning.intValue()), warning);

    integersToMLevels = Collections.unmodifiableMap( tmp );

    tmp = new HashMap();
    tmp.put( all.getSeverity(), all);
    tmp.put( config.getSeverity(), config);
    tmp.put( fine.getSeverity(), fine);
    tmp.put( finer.getSeverity(), finer);
    tmp.put( finest.getSeverity(), finest);
    tmp.put( info.getSeverity(), info);
    tmp.put( off.getSeverity(), off);
    tmp.put( severe.getSeverity(), severe);
    tmp.put( warning.getSeverity(), warning);

    namesToMLevels = Collections.unmodifiableMap( tmp );
    }

    Object level;
    int    intval;
    String lvlstring;

    public int intValue()
    { return intval; }

    public Object asJdk14Level()
    { return level; }

    public String getSeverity()
    { return lvlstring; }

    public String toString()
    { return this.getClass().getName() + this.getLineHeader(); }

    public String getLineHeader()
    { return "[" + lvlstring + ']';}



    private MLevel(Object level, int intval, String lvlstring)
    {
    this.level = level;
    this.intval = intval;
    this.lvlstring = lvlstring;
    }
}
 

 

package java.util.logging;

import java.util.*;
import java.security.*;
import java.lang.ref.WeakReference;
 
private static final int offValue = Level.OFF.intValue();
    private volatile int levelValue;  // current effective level value
    /** * Check if a message of the given level would actually be logged
 * by this logger. This check is based on the Loggers effective level,
 * which may be inherited from its parent. *
 * @param level a message logging level
 * @return true if the given message level is currently being logged. */
时间: 2024-11-03 09:57:31

java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE 的理解的相关文章

Exception in thread "main" java.lang.Exception: 网页内容获取异常!Http Status Code:403

问题描述 packagecom.mobile.util;importjava.util.regex.Matcher;importjava.util.regex.Pattern;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.NameValuePair;importorg.apache.commons.httpclient.methods.PostMethod;importorg.

connection-Connection has been abandoned :java.lang.Exception

问题描述 Connection has been abandoned :java.lang.Exception 使用的DBCP连接池和Mysql数据库,偶尔会出现这种异常,不知是什么导致的,并且在出现这个异常的地方进行对Exception的catch,但是奇怪的时捕获不了这种异常,异常一直被传回虚拟机然后打印,请哪位大侠指导一下,具体的异常如下 警告: Connection has been abandoned PooledConnection[com.mysql.jdbc.Connection

用java2word报错:java.lang.Exception: 初始化类库出错,请检查是否注册了组件 Word.Application

问题描述 小弟要做一个java操作word的应用,在网上找了很多之后决定使用java2word.可是程序报如下错误:java.lang.Exception:初始化类库出错,请检查是否注册了组件Word.Application.注册命令为'regsvr32文件名'.望高手指点一二.小弟感激不尽. 解决方案 解决方案二:java软件安装的不正确啊,重新装个试试!!解决方案三:那个JAVA软件啊?你指的是java2word还是myeclipse还是jdk?解决方案四:怎么没人答啊?这帖子不能沉啊!!!

谈一谈JUnit神奇的报错 java.lang.Exception:No tests found matching

最近在学习Spring+SpringMVC+MyBatis,一个人的挖掘过程确实有点艰难,尤其是有一些神奇的报错让你会很蛋疼.特别是接触一些框架还是最新版本的时候,会因为版本问题出现很多错误,欢迎大家一起学习交流 这篇就说一下困扰我昨晚2小时的一个报错,nitializationError(org.junit.runner.manipulation.Filter)或者No tests found matching异常,查阅了很多资料,总结一下这些情况和解决办法. 1.最容易发现的错误,就如报错所

Exception in thread main java.lang.NoClassDefFoundError错误解决方法_java

错误描述 javac helloworld.java能够通过.但是java helloworld出现错误: hadoop@xuwei-erplab:~/jarfile$ java HelloWorld Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong name: org/xuwei/HelloWorld) at java.lang.ClassLoader.defineClass1(N

Java异常的栈轨迹(Stack Trace)

3.fillInStackTrace() 我们在前面也提到了这个方法.要说清楚这个方法,首先要讲一下捕获异常之后重新抛出的问题.在catch代码块中捕获到异常,打印栈轨迹,又重新throw出去.在上一级的方法调用中,再捕获这个异常并且打印出栈轨迹信息.这两个栈轨迹信息会一样吗?我们看一下代码: public class TestPrintStackTrace {     public static void f() throws Exception{         throw new Exce

解析Java中所有错误和异常的父类java.lang.Throwable_java

在java语言中,错误类的基类是java.lang.Error,异常类的基类是java.lang.Exception. 1)相同点:java.lang.Error和java.lang.Exception都是java.lang.Throwable的子类,因此java.lang.Error和java.lang.Exception自身及其子类都可以作为throw的使用对象,如:throw new MyError();和throw new MyException();其中,MyError类是java.l

weblogic部署web项目报错java.lang.ClassCastException

问题描述 tomcat本地测试都是可以的,但在weblogic上部署,就会报错:java.lang.RuntimeException:UnabletocreateXMLReaderatorg.jasig.cas.client.util.XmlUtils.getXmlReader(XmlUtils.java:58)atorg.jasig.cas.client.util.XmlUtils.getTextForElement(XmlUtils.java:130)atorg.jasig.cas.clie

struts2异常java.lang.NoSuchMethodException: com.struts.action.UserAction.create()

问题描述 原来用的struts2.0版本,运行项目没有问题.后来换了struts2.2.1版本后,只要访问Action,都会出现java.lang.NoSuchMethodException: com.struts.action.UserAction.create()类似的错误,就是说Action中找不到create这个方法.struts.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE stru