久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

mysql - 如何顯式修改數據庫連接超時時間

瀏覽:117日期:2022-06-21 18:19:50

問題描述

spring + mybatis

redis.incr(key); //redis計數加一try{ dbOPerHere(); //數據庫操作}catch (Exception e){ //若數據庫操作失敗 減一 redis.decr(key); }

想模擬網路異常 數據庫連接超時異常 通過如下方式模擬數據庫連接異常

sudo iptables -A INPUT -p tcp --dport 3306 -j DROP

但發現要等差不多三分鐘 才會有超時異常另外一個奇怪現象 同樣的數據源配置 若換成測試服務器 超時時間為6分鐘 不知何故

Caused by: java.net.ConnectException: Connection timed out

如何顯式設置數據庫連接超時時間(如超時時間5秒), 不管是配置數據源 還是 修改mysql服務器的變量?使用的數據源如下

<bean destroy-method='close'>

或修改mysql服務器變量

>show variables like ’%timeout%’;+-----------------------------+----------+| Variable_name | Value |+-----------------------------+----------+| connect_timeout | 10 || delayed_insert_timeout | 300 || innodb_flush_log_at_timeout | 1|| innodb_lock_wait_timeout | 50 || innodb_rollback_on_timeout | OFF || interactive_timeout | 28800 || lock_wait_timeout | 31536000 || net_read_timeout | 30 || net_write_timeout | 60 || rpl_stop_slave_timeout | 31536000 || slave_net_timeout | 3600 || wait_timeout| 28800 |+-----------------------------+----------+

問題解答

回答1:

/** * <strong>BasicDataSource does NOT support this method. </strong> * * <p>Set the login timeout (in seconds) for connecting to the * database.</p> * <p> * Calls {@link #createDataSource()}, so has the side effect * of initializing the connection pool.</p> * * @param loginTimeout The new login timeout, or zero for no timeout * @throws UnsupportedOperationException If the DataSource implementation * does not support the login timeout feature. * @throws SQLException if a database access error occurs */ public void setLoginTimeout(int loginTimeout) throws SQLException {// This method isn’t supported by the PoolingDataSource returned by// the createDataSourcethrow new UnsupportedOperationException('Not supported by BasicDataSource');//createDataSource().setLoginTimeout(loginTimeout); }

* <strong>BasicDataSource does NOT support this method. </strong> *

以上是dbcp連接池的源代碼,不知道這個LoginTimeout()具體是做什么的,僅供參考,并期待問題后續。

相關文章:
主站蜘蛛池模板: 长泰县| 巴马| 常熟市| 和平区| 济源市| 长丰县| 嘉兴市| 神木县| 赤峰市| 满城县| 巢湖市| 太仓市| 甘孜| 平南县| 江达县| 滦平县| 冀州市| 凤山市| 碌曲县| 安宁市| 日土县| 留坝县| 德令哈市| 中牟县| 松潘县| 牙克石市| 苏州市| 阿拉尔市| 石台县| 乡宁县| 武陟县| 芜湖县| 龙陵县| 崇文区| 盐津县| 邯郸县| 铜陵市| 富民县| 禄劝| 南开区| 香港|