2 u011935480 u011935480 于 2016.04.11 18:50 提问

关于Java服务长时间运行出现各种bug问题,可能运行几天没问题,但是运行十几天就会出现各种bug

服务使用的是ScheduledThreadPoolExecuto定时任务,有使用到全局变量,数据库连接池使用的是c3p0,我感觉出现问题的原因可能就是这三个里哪个导致的,程序是没问题的,就是运行久了就出现各种问题了,而且很莫明奇妙,比如本来是好好的运行久了日志中的中文从那个时刻起往后全都乱码了。请问这是怎么回事?

定时任务:
ScheduledThreadPoolExecutor bookClickScheduled = new ScheduledThreadPoolExecutor(10);
int checkPHPConfigCycle = Integer.parseInt(Config.getConfig("CheckPHPConfigCycle"));
bookClickScheduled.scheduleWithFixedDelay(new CheckPhpConfigTask(), 0, checkPHPConfigCycle, TimeUnit.MINUTES);

连接池配置:

            <property value="oracle.jdbc.driver.OracleDriver" name="driverClass"/>

            <property value="jdbc:oracle:thin:@10.97.190.14:1521:cmfudv1" name="jdbcUrl"/>

        <property value="" name="user"/>

            <property value="" name="password"/>

    <property value="1" name="minPoolSize"/>

    <property value="2" name="maxPoolSize"/>

    <property value="1" name="initialPoolSize"/>

    <property value="60" name="maxIdleTime"/>

    <property value="1" name="acquireIncrement"/>


    <property value="0" name="maxStatements"/>

    <property value="60" name="idleConnectionTestPeriod"/>

    <property value="30" name="acquireRetryAttempts"/>


    <property value="true" name="breakAfterAcquireFailure"/>

</bean>


    看了一下日志,貌似是服务重启启动了

    STATUS | wrapper  | 2016/04/09 00:55:01 | TERM trapped.  Shutting down.

STATUS | wrapper | 2016/04/09 00:55:02 | <-- Wrapper Stopped
STATUS | wrapper | 2016/04/09 00:55:02 | --> Wrapper Started as Daemon
STATUS | wrapper | 2016/04/09 00:55:02 | Java Service Wrapper Community Edition 64-bit 3.5.27
STATUS | wrapper | 2016/04/09 00:55:02 | Copyright (C) 1999-2015 Tanuki Software, Ltd. All Rights Reserved.
STATUS | wrapper | 2016/04/09 00:55:02 | http://wrapper.tanukisoftware.com
STATUS | wrapper | 2016/04/09 00:55:02 |
STATUS | wrapper | 2016/04/09 00:55:02 | Launching a JVM...
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: Initializing...
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager:
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: WARNING - Unable to load the Wrapper's native library because none of the
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: following files:
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: libwrapper-linux-x86-64.so
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: libwrapper.so
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: could be located on the following java.library.path:
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: /usr/local/src/javaService/Baiduping2Service/bin/../lib
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: Please see the documentation for the wrapper.java.library.path
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: configuration property.
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager: System signals will not be handled correctly.
INFO | jvm 1 | 2016/04/09 00:55:02 | WrapperManager:
INFO | jvm 1 | 2016/04/09 00:55:03 | SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
INFO | jvm 1 | 2016/04/09 00:55:03 | SLF4J: Defaulting to no-operation (NOP) logger implementation
INFO | jvm 1 | 2016/04/09 00:55:03 | SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
INFO | jvm 1 | 2016/04/09 00:55:03 | INFO - Log4j - ????
INFO | jvm 1 | 2016/04/09 00:55:03 | INFO - MLog - MLog clients using log4j logging.
INFO | jvm 1 | 2016/04/09 00:55:03 | INFO - C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
INFO | jvm 1 | 2016/04/09 00:55:03 | INFO - stractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> true, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kflt9f1wh77y1c9vh4r|38c52200, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9f1wh77y1c9vh4r|38c52200, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@oracoredb2.qdintra.com:1521:cmfu, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
INFO | jvm 1 | 2016/04/09 00:55:04 | INFO - stractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> true, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kflt9f1wh77y1c9vh4r|3ee7f6eb, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9f1wh77y1c9vh4r|3ee7f6eb, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@orabooksyncdb.qdintra.com:1521:cmfu162, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
INFO | jvm 1 | 2016/04/09 00:57:12 | INFO - Log4j - bookID:3623267,res:true
INFO | jvm 1 | 2016/04/09 00:57:14 | INFO - Log4j - bookID:3564278,res:true
INFO | jvm 1 | 2016/04/09 00:57:18 | INFO - Log4j - bookID:3630677,res:true
STATUS | wrapper | 2016/04/09 01:30:01 | TERM trapped. Shutting down.
STATUS | wrapper | 2016/04/09 01:30:02 | <-- Wrapper Stopped
STATUS | wrapper | 2016/04/09 01:30:02 | --> Wrapper Started as Daemon
STATUS | wrapper | 2016/04/09 01:30:02 | Java Service Wrapper Community Edition 64-bit 3.5.27
STATUS | wrapper | 2016/04/09 01:30:02 | Copyright (C) 1999-2015 Tanuki Software, Ltd. All Rights Reserved.
STATUS | wrapper | 2016/04/09 01:30:02 | http://wrapper.tanukisoftware.com
STATUS | wrapper | 2016/04/09 01:30:02 |
STATUS | wrapper | 2016/04/09 01:30:02 | Launching a JVM...
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: Initializing...
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager:
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: WARNING - Unable to load the Wrapper's native library because none of the
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: following files:
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: libwrapper-linux-x86-64.so
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: libwrapper.so
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: could be located on the following java.library.path:
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: /usr/local/src/javaService/Baiduping2Service/bin/../lib
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: Please see the documentation for the wrapper.java.library.path
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: configuration property.
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager: System signals will not be handled correctly.
INFO | jvm 1 | 2016/04/09 01:30:02 | WrapperManager:
INFO | jvm 1 | 2016/04/09 01:30:03 | SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
INFO | jvm 1 | 2016/04/09 01:30:03 | SLF4J: Defaulting to no-operation (NOP) logger implementation
INFO | jvm 1 | 2016/04/09 01:30:03 | SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
INFO | jvm 1 | 2016/04/09 01:30:03 | INFO - Log4j - ????
INFO | jvm 1 | 2016/04/09 01:30:03 | INFO - MLog - MLog clients using log4j logging.
INFO | jvm 1 | 2016/04/09 01:30:03 | INFO - C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
INFO | jvm 1 | 2016/04/09 01:30:03 | INFO - stractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> true, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kflt9f1wig8b6168q1b9|ec0a9f9, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9f1wig8b6168q1b9|ec0a9f9, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@oracoredb2.qdintra.com:1521:cmfu, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
INFO | jvm 1 | 2016/04/09 01:30:04 | INFO - stractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> true, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kflt9f1wig8b6168q1b9|6708f8e0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9f1wig8b6168q1b9|6708f8e0, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@orabooksyncdb.qdintra.com:1521:cmfu162, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
INFO | jvm 1 | 2016/04/09 01:30:06 | INFO - Log4j - bookID:1659706,res:true
INFO | jvm 1 | 2016/04/09 01:30:06 | INFO - Log4j - bookID:3593166,res:true
STATUS | wrapper | 2016/04/09 02:05:01 | TERM trapped. Shutting down.
STATUS | wrapper | 2016/04/09 02:05:02 | <-- Wrapper Stopped
STATUS | wrapper | 2016/04/09 02:05:02 | --> Wrapper Started as Daemon
STATUS | wrapper | 2016/04/09 02:05:02 | Java Service Wrapper Community Edition 64-bit 3.5.27
STATUS | wrapper | 2016/04/09 02:05:02 | Copyright (C) 1999-2015 Tanuki Software, Ltd. All Rights Reserved.
STATUS | wrapper | 2016/04/09 02:05:02 | http://wrapper.tanukisoftware.com
STATUS | wrapper | 2016/04/09 02:05:02 |
STATUS | wrapper | 2016/04/09 02:05:02 | Launching a JVM...
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: Initializing...
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager:
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: WARNING - Unable to load the Wrapper's native library because none of the
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: following files:
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: libwrapper-linux-x86-64.so
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: libwrapper.so
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: could be located on the following java.library.path:
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: /usr/local/src/javaService/Baiduping2Service/bin/../lib
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: Please see the documentation for the wrapper.java.library.path
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: configuration property.
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager: System signals will not be handled correctly.
INFO | jvm 1 | 2016/04/09 02:05:02 | WrapperManager:
INFO | jvm 1 | 2016/04/09 02:05:03 | SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
INFO | jvm 1 | 2016/04/09 02:05:03 | SLF4J: Defaulting to no-operation (NOP) logger implementation
INFO | jvm 1 | 2016/04/09 02:05:03 | SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
INFO | jvm 1 | 2016/04/09 02:05:03 | INFO - Log4j - ????
INFO | jvm 1 | 2016/04/09 02:05:03 | INFO - MLog - MLog clients using log4j logging.
INFO | jvm 1 | 2016/04/09 02:05:03 | INFO - C3P0Registry - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
INFO | jvm 1 | 2016/04/09 02:05:04 | INFO - stractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> true, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kflt9f1wjp8pwwokymc|38c52200, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9f1wjp8pwwokymc|38c52200, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@oracoredb2.qdintra.com:1521:cmfu, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
INFO | jvm 1 | 2016/04/09 02:05:04 | INFO - stractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> true, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> z8kflt9f1wjp8pwwokymc|3ee7f6eb, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> oracle.jdbc.driver.OracleDriver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> z8kflt9f1wjp8pwwokymc|3ee7f6eb, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, jdbcUrl -> jdbc:oracle:thin:@orabooksyncdb.qdintra.com:1521:cmfu162, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 5, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

1个回答

u011935480
u011935480   2016.04.11 19:06

定时任务:
ScheduledThreadPoolExecutor bookClickScheduled = new ScheduledThreadPoolExecutor(10);
int checkPHPConfigCycle = Integer.parseInt(Config.getConfig("CheckPHPConfigCycle"));
bookClickScheduled.scheduleWithFixedDelay(new CheckPhpConfigTask(), 0, checkPHPConfigCycle, TimeUnit.MINUTES);

连接池配置:


name="jdbcUrl"/>


<!--连接池中保留的最小连接数。 -->

<!--连接池中保留的最大连接数。Default: 15 -->

<!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->

<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->

<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->

<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->

<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->

<!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 -->

<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 -->

    <property value="true" name="breakAfterAcquireFailure"/>

</bean>
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!