Weblogic连接池设置和监控

weblogic连接池设置和监控

1.weblogic的连接池的线程数可以设置初始值和最大值。 
连接池,把短连接变成了长连接。这样减少了网络IO的消耗,设置了连接池之后可以在操作系统上看到如下信息:

iostat -natpl | grep 3306

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45899 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45886 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45851 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45859 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45836 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45887 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45898 TIME_WAIT –

tcp 0 0 ::ffff:10.10.101.2:3306 ::ffff:222.74.214.122:9660 ESTABLISHED –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45850 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:7001 ::ffff:127.0.0.1:46475 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45863 TIME_WAIT –

tcp 0 0 ::1:7001 ::1:37445 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45888 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45861 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45873 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45840 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45860 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45835 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45891 TIME_WAIT –

tcp 0 0 ::1:56622 ::1:42622 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45866 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45871 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45876 TIME_WAIT –

tcp 0 0 ::ffff:127.0.0.1:3306 ::ffff:127.0.0.1:45892 TIME_WAIT –

在数据库中可以看到:

show full processlist;

| 2075 | root | localhost:44194 | coa | Sleep | 368 | | NULL |

| 2076 | root | localhost:44195 | coa | Sleep | 366 | | NULL |

| 2077 | root | localhost:44196 | coa | Sleep | 365 | | NULL |

| 2078 | root | localhost:44197 | coa | Sleep | 364 | | NULL |

| 2079 | root | localhost:44198 | coa | Sleep | 362 | | NULL |

| 2080 | root | localhost:44199 | coa | Sleep | 361 | | NULL |

| 2081 | root | localhost:44200 | coa | Sleep | 359 | | NULL |

| 2082 | root | localhost:44201 | coa | Sleep | 358 | | NULL |

| 2083 | root | localhost:44202 | coa | Sleep | 356 | | NULL |

| 2084 | root | localhost:44203 | coa | Sleep | 355 | | NULL |

| 2085 | root | localhost:44204 | coa | Sleep | 353 | | NULL |

| 2086 | root | localhost:44205 | coa | Sleep | 352 | | NULL |

| 2087 | root | localhost:44206 | coa | Sleep | 350 | | NULL |

| 2088 | root | localhost:44207 | coa | Sleep | 348 | | NULL |

| 2089 | root | localhost:44208 | coa | Sleep | 347 | | NULL |

| 2090 | root | localhost:44209 | coa | Sleep | 345 | | NULL |

| 2091 | root | localhost:44210 | coa | Sleep | 344 | | NULL |

| 2092 | root | localhost:44211 | coa | Sleep | 342 | | NULL |

| 2093 | root | localhost:44212 | coa | Sleep | 340 | | NULL |

| 2094 | root | localhost:44213 | coa | Sleep | 339 | | NULL |

| 2095 | root | localhost:44214 | coa | Sleep | 337 | | NULL

例如,初始容量:5 最大容量:20 
最大的容量,也就是说可以提供多少个连接,就是说数据库这个房子总共有多少个门,那么这个实例里就是有20个门。 
初始值也就是说平时就给程序连接开几个门,这几个门始终开着,连接过来的时候,可以不用再去开辟新的连接。 
2.非活动连接超时时间 
如果单设置了最大值和最小值而没有设置此值,那么如果遇到程序不释放连接、在监控中是看不到泄漏的连接的。 
这次设置了10秒。之后在weblogic的日志里看到了自动强制释放连接的记录

<Oct
27, 2016
3:50:27
PM
CST>
<Warning>
<JDBC>
<BEA-001153>
<Forcibly
releasing
inactive/harvested
connection

 

weblogic.jdbc.wrapper.PoolConnection_com_mysql_jdbc_JDBC4Connection@280

在数据库日志里看到了weblogic过来杀进程的信息:

2700 Query /* mysql-connector-java-commercial-5.1.17 ( Revision: ${bzr.revision-id} ) */


SHOW VARIABLES WHERE Variable_name =‘language’

OR Variable_name = ‘interactive_timeout’
OR Variable_name = ‘wait_timeout’


OR Variable_name = ‘character_set_client’
OR Variable_name = ‘character_set_connection’


OR Variable_name = ‘character_set_server’
OR Variable_name = ‘tx_isolation’


OR Variable_name = ‘lower_case_table_names’

OR Variable_name = ‘sql_mode’
OR Variable_name = ‘query_cache_type’


OR Variable_name = ‘query_cache_size’


OR Variable_name = ‘init_connect’

  •  

    3、泄漏连接 
    在weblogic的连接池监控中,可以定义要监控的选项,默认是没有几项的,一般是监控最大可用数量、最大活动连接计数 、 泄漏连接计数、 其中泄露的连接计数就是常说的不释放的连接所致。 
    解决代码如下:

    Connection connection=null;


    try{


    try{

    connection = getConnectionByJndi();

    }catch(Exception e){


    return ;

    }

     

    }catch(Exception e){}

    finally{

    //***在这里关闭连接***///

    }

以下文章点击率最高

Loading…


发表评论

电子邮件地址不会被公开。 必填项已用*标注