NutzCN Logo
问答 关于数据库操作工具类的报错问题
发布于 2494天前 作者 qq_3ef73b2c 5676 次浏览 复制 上一个帖子 下一个帖子
标签:
public JSONObject Login(JSONObject jsonObj) throws BusinessException {
		// 登录功能
		// 接收三个参数:adminid 管理员名、adminPass 管理员密码、captcha 验证码
		JSONObject result = new JSONObject();
		MD5 md = new MD5();
		String id = jsonObj.getString("member_id");
		String pwd = jsonObj.getString("pwd");
		String sql = "select pwd,salt from admin_table where member_id=?";
		mysql.OPenDb(DBMysql.DB_TYPE_MASTER);// 选择主库进行read
		Object[] params = { id };
		Admin admin = mysql.query(Admin.class, sql, params);
		// database pwd=md5(md5(request pwd)+database salt))
		String pwlt = md.Encode(md.Encode(pwd) + admin.getSalt());
		try {
			if (pwlt.equals(admin.getPwd())) {
				result.element("code", InterfaceErrorCode.NO_ERROR).element(
						"info", InterfaceErrorInfo.NO_ERROR);
				req.getSession().setAttribute("admin", admin);
			}
		} catch (Exception e) {
			result.element("info", BusinessException.Translate(e.getMessage()));
			e.printStackTrace();
		}
		mysql.close();
		return result;
	}

/**
* 释放资源
*/
public void close() {
try {
if (this.rs != null)
this.rs.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
if (this.conn != null)
this.conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
一月 17, 2018 11:13:16 上午 com.alibaba.druid.pool.DruidDataSource error
严重: abandon connection, owner thread: http-apr-8080-exec-3, connected at : 1516158436474, open stackTrace
at java.lang.Thread.getStackTrace(Thread.java:1589)
at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1068)
at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2723)
at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:992)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:984)
at LMPack.Tools.Database.DBMysql.getMasterConnection(DBMysql.java:69)
at LMPack.Tools.Database.DBMysql.OPenDb(DBMysql.java:111)
at LMPack.Service.Restful.IEnterance.wwoTest(IEnterance.java:154)
at LMPack.Service.Restful.IEnterance$FM$wwoTest$4e8cf7a5f1235d40ec6785e1e6bddfad.invoke(IEnterance.java)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2555)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
ownerThread current state is WAITING, current stackTrace
at sun.misc.Unsafe.park(Native Method)
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 org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:745)

=====================================================
这是properties
removeAbandoned:true

removeAbandonedTimeout:1800

logAbandoned:true

@wendal

22 回复

用 插入代码 按钮重新贴

一月 17, 2018 11:13:16 上午 com.alibaba.druid.pool.DruidDataSource error
严重: abandon connection, owner thread: http-apr-8080-exec-3, connected at : 1516158436474, open stackTrace
	at java.lang.Thread.getStackTrace(Thread.java:1589)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1068)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
	at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2723)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:992)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:984)
	at LMPack.Tools.Database.DBMysql.getMasterConnection(DBMysql.java:69)
	at LMPack.Tools.Database.DBMysql.OPenDb(DBMysql.java:111)
	at LMPack.Service.Restful.IEnterance.wwoTest(IEnterance.java:154)
	at LMPack.Service.Restful.IEnterance$FM$wwoTest$4e8cf7a5f1235d40ec6785e1e6bddfad.invoke(IEnterance.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2555)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
ownerThread current state is WAITING, current stackTrace
	at sun.misc.Unsafe.park(Native Method)
	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 org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:104)
	at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:32)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

public JSONObject Login(JSONObject jsonObj) throws BusinessException {
		// 登录功能
		// 接收三个参数:adminid 管理员名、adminPass 管理员密码、captcha 验证码
		JSONObject result = new JSONObject();
		MD5 md = new MD5();
		String id = jsonObj.getString("member_id");
		String pwd = jsonObj.getString("pwd");
		String sql = "select pwd,salt from admin_table where member_id=?";
		mysql.OPenDb(DBMysql.DB_TYPE_MASTER);// 选择主库进行read
		Object[] params = { id };
		Admin admin = mysql.query(Admin.class, sql, params);
		// database pwd=md5(md5(request pwd)+database salt))
		String pwlt = md.Encode(md.Encode(pwd) + admin.getSalt());
		try {
			if (pwlt.equals(admin.getPwd())) {
				result.element("code", InterfaceErrorCode.NO_ERROR).element(
						"info", InterfaceErrorInfo.NO_ERROR);
				req.getSession().setAttribute("admin", admin);
			}
		} catch (Exception e) {
			result.element("info", BusinessException.Translate(e.getMessage()));
			e.printStackTrace();
		}
		mysql.close();
		return result;
	}
/**
	 * 释放资源
	 */
	public void close() {
		try {
			if (this.rs != null)
				this.rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (this.conn != null)
				this.conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

mysql这个实例的类贴一下看看

package LMPack.Tools.Database;

import java.io.IOException;
import java.io.InputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.pool.DruidPooledConnection;

public class DBMysql {
	private static DruidDataSource dataSource;
	private static Properties properties;

	public static final int DB_TYPE_MASTER = 1;
	public static final int DB_TYPE_SLAVE = 2;

	private DruidPooledConnection conn;
	private ResultSet rs;
	private static InputStream in;

	static {
		DBMysql.init();
	}

	private static void init() {
		properties = new Properties();
		try {
			in = DBMysql.class.getClassLoader().getResourceAsStream(
					"config.properties");
			if (in == null) {
				throw new Exception("config input stream open error");
			}
			properties.load(in);
			dataSource = (DruidDataSource) DruidDataSourceFactory
					.createDataSource(properties);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	private static DruidPooledConnection getMasterConnection() {
		DruidPooledConnection conn = null;
		try {
			dataSource.setDriverClassName(properties
					.getProperty("driverClassName"));
			dataSource.setUrl(properties.getProperty("url"));
			dataSource.setUsername(properties.getProperty("username"));
			dataSource.setPassword(properties.getProperty("password"));
			conn = dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	private static DruidPooledConnection getSlaveConnection() {
		DruidPooledConnection conn = null;
		Random r = new Random(System.currentTimeMillis());
		List<String> lstConfig = new ArrayList<String>();
		String strConfig1 = properties.getProperty("url") + ","
				+ properties.getProperty("username1") + ","
				+ properties.getProperty("password1");
		String strConfig2 = properties.getProperty("url2") + ","
				+ properties.getProperty("username2") + ","
				+ properties.getProperty("password2");
		String strConfig3 = properties.getProperty("url2") + ","
				+ properties.getProperty("username3") + ","
				+ properties.getProperty("password3");
		lstConfig.add(0, strConfig1);
		lstConfig.add(1, strConfig2);
		lstConfig.add(2, strConfig3);
		try {
			dataSource.setConnectionProperties(lstConfig.get(
					r.nextInt(lstConfig.size())).toString());
			conn = dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public DBMysql() {
		this.conn = null;
	}

	public void OPenDb(int dbType) {
		this.close();

		switch (dbType) {
		case DBMysql.DB_TYPE_MASTER:
			this.conn = DBMysql.getMasterConnection();
			break;
		case DBMysql.DB_TYPE_SLAVE:
			this.conn = DBMysql.getSlaveConnection();
			break;
		default:
			break;
		}
	}

	/**
	 * 返回多条记录
	 */
	public JSONArray getObjectListBySQL(String sql, Object... params) {
		// 从连接池获取数据库连接
		if (this.conn == null)
			return null;
		JSONArray jsonArray = new JSONArray();
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			// 预编译SQL语句
			pstmt = conn.prepareStatement(sql);

			if (params != null) {
				for (int i = 0; i < params.length; i++) {
					pstmt.setObject(i + 1, params[i]);
				}
			}
			rs = pstmt.executeQuery();
			// 获取结果集列数
			int columCount = rs.getMetaData().getColumnCount();
			while (rs.next()) {
				JSONObject jsonObject = new JSONObject();
				for (int i = 0; i < columCount; i++) {
					String name = rs.getMetaData().getColumnName(i + 1);
					Object val = rs.getObject(i + 1);
					if (name.equals("createtime")) {
						val = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
								.format(val);
					}
					jsonObject.put(name, val);
				}
				jsonArray.add(jsonObject);
			}
			return jsonArray;

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				pstmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return jsonArray;
	}

	/**
	 * 返回查询结果的第一条数据
	 */
	public JSONObject getObjectBySQL(String sql, Object... params) {
		// 从连接池获取数据库连接
		if (this.conn == null)
			return null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			// 预编译SQL语句
			pstmt = conn.prepareStatement(sql);
			if (params != null) {
				for (int i = 0; i < params.length; i++) {
					pstmt.setObject(i + 1, params[i]);
				}
			}
			rs = pstmt.executeQuery();
			// 获取结果集列数
			int columCount = rs.getMetaData().getColumnCount();
			// columCount
			if (rs.next()) {
				JSONObject jsonObject = new JSONObject();
				for (int i = 0; i < columCount; i++) {
					jsonObject.put(rs.getMetaData().getColumnName(i + 1),
							rs.getObject(i + 1));
				}
				return jsonObject;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				pstmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * 查询一条记录,返回对应的对象
	 */
	public <T> T query(Class<T> clazz, String sql, Object... args) {
		T obj = null;
		PreparedStatement ps = null;
		try {
			// 1、获取connection
			if (this.conn == null)
				return null;
			// 2、获取PreparedStatement
			ps = conn.prepareStatement(sql);
			// 3、填充占位符
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject(i + 1, args[i]);
				}
			}
			// 4、进行查询,得到ResultSet
			rs = ps.executeQuery();
			// 5、准备一个Map<String,Object>:(前提是结果集中要有记录)
			if (rs.next()) {
				Map<String, Object> values = new HashMap<String, Object>();
				// 6、得到ResultSetMetaData对象
				ResultSetMetaData rsd = rs.getMetaData();
				// 7、处理ResultSet,把指针向下移动一个单位
				// 8、由ResultSetMetaData对象得到结果集中有多少列
				int lieshu = rsd.getColumnCount();
				// 9、由ResultSetMetaData对象得到每一列的别名,由ResultSet得到具体每一列的值
				for (int i = 0; i < lieshu; i++) {
					String lieming = rsd.getColumnLabel(i + 1);
					Object liezhi = rs.getObject(i + 1);
					// 10、填充Map对象
					values.put(lieming, liezhi);
				}
				// 11、用反射创建Class对应的对象
				obj = clazz.newInstance();
				// 12、遍历Map对象,用反射填充对象的属性值,
				for (Map.Entry<String, Object> ent : values.entrySet()) {
					String name = ent.getKey();
					Object value = ent.getValue();
					// 用反射赋值
					ReflectionUtils.setFieldValue(obj, name, value);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return obj;

	}

	/**
	 * 更新数据,返回影响行数
	 */
	public int executeUpdateBySQL(String sql, Object... params) {
		// 从连接池获取数据库连接
		if (this.conn == null)
			return -1;
		PreparedStatement pstmt = null;
		try {
			// 预编译SQL语句
			pstmt = conn.prepareStatement(sql);

			for (int i = 0; i < params.length; i++) {

				pstmt.setObject(i + 1, params[i]);
			}

			return pstmt.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				pstmt.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return 0;
	}

	/**
	 * 释放资源
	 */
	public void close() {
		try {
			if (this.rs != null)
				this.rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			if (this.conn != null)
				this.conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void beginTransaction() throws Exception {
		if (this.conn != null) {
			if (conn.getAutoCommit()) {
				conn.setAutoCommit(false);
			}
		}
	}

	public void commitTransaction() throws Exception {
		if (this.conn != null) {
			if (!conn.getAutoCommit()) {
				conn.commit();
			}
		}
	}

	public void rollbackTransaction() {
		try {
			if (this.conn != null) {
				if (!conn.getAutoCommit()) {
					conn.rollback();
				}
			}
		} catch (Exception e) {
		}
	}

	public DruidPooledConnection getCurrentConnection() {
		if (conn == null) {
			return null;
		}
		return this.conn;
	}

}

擦, 为啥不用NutDao?

我也想用啊,领导不用.....Mvc模式用的是nutz

我也很无奈很绝望啊

这样DBMysql 只要切换一次主从, master的conn是必丢啊

但是每次用完一个conn 都有关闭,大神,怎么解决这个bug?

领导不用啊我也没办法,我这个bug有解决方法吗?

redis.address=192.168.1.23
redis.port=12302

#SCEmail
apiUser=testmall
apiKey=ZckubHenqQfzYzAy
from=Local_Mall@qq.com

#druid
driverClassName:com.mysql.jdbc.Driver
url:jdbc:mysql://192.168.1.23/LocalMall?useUnicode=true&characterEncoding=utf-8
username:dev
password:dev12345

url1:jdbc:mysql://192.168.1.23/LocalMall?useUnicode=true&characterEncoding=utf-8
username1:dev
password1:dev12345

url2:jdbc:mysql://192.168.1.23/LocalMall?useUnicode=true&characterEncoding=utf-8
username2:dev
password2:dev12345

url3:jdbc:mysql://192.168.1.23/LocalMall?useUnicode=true&characterEncoding=utf-8
username3:dev
password3:dev12345

filters:wall
maxActive:20
initialSize:1
maxWait:60000
minIdle:10
timeBetweenEvictionRunsMillis:60000
minEvictableIdleTimeMillis:300000
validationQuery:SELECT 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
maxOpenPreparedStatements:20
removeAbandoned:true
#removeAbandonedTimeout:1800 
logAbandoned:true

我只要把这个注释去掉,就不会有这个错,但是就报另一个错,等我插给你

18-01-17 11:26:15.782 DEBUG [http-apr-8080-exec-3] Found mapping for [GET] path=/wwo : IEnterance.wwoTest(IEnterance.java:151)
java.lang.NumberFormatException: For input string: "1800 "
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:492)
	at java.lang.Integer.parseInt(Integer.java:527)
	at com.alibaba.druid.pool.DruidDataSourceFactory.config(DruidDataSourceFactory.java:294)
	at com.alibaba.druid.pool.DruidDataSourceFactory.createDataSource(DruidDataSourceFactory.java:143)
	at com.alibaba.druid.pool.DruidDataSourceFactory.createDataSource(DruidDataSourceFactory.java:137)
	at LMPack.Tools.Database.DBMysql.init(DBMysql.java:49)
	at LMPack.Tools.Database.DBMysql.<clinit>(DBMysql.java:36)
	at LMPack.Service.Restful.IEnterance.wwoTest(IEnterance.java:152)
	at LMPack.Service.Restful.IEnterance$FM$wwoTest$4e8cf7a5f1235d40ec6785e1e6bddfad.invoke(IEnterance.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2555)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
18-01-17 11:26:15.921 WARN [http-apr-8080-exec-3] Error@/wwo :
java.lang.NullPointerException
	at LMPack.Tools.Database.DBMysql.getMasterConnection(DBMysql.java:64)
	at LMPack.Tools.Database.DBMysql.OPenDb(DBMysql.java:110)
	at LMPack.Service.Restful.IEnterance.wwoTest(IEnterance.java:154)
	at LMPack.Service.Restful.IEnterance$FM$wwoTest$4e8cf7a5f1235d40ec6785e1e6bddfad.invoke(IEnterance.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2555)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

那你让领导解决就好了

1800那个错误, 把那一行删掉就没事啦, 不过, 这是治标不治本的

根源还是连接泄露, 没有全部close掉

mysql是实例变量? 那么多线程不就死了?

好的,谢谢大神

添加回复
请先登陆
回到顶部