數(shù)據(jù)庫最大連接數(shù)原理
1、JAVA做一個循環(huán),每做一次事務(wù)(CRUD)加一個連接,一個連接相當(dāng)于占2M內(nèi)存。
50秒后自動釋放。
如果超過最大連接數(shù)報錯如下:
ORA-12519: TNS:no appropriate service handler found 解決
有時候連得上數(shù)據(jù)庫,有時候又連不上.
可能是數(shù)據(jù)庫上當(dāng)前的連接數(shù)目已經(jīng)超過了它能夠處理的最大值.
select count(*) from v$process --當(dāng)前的連接數(shù)
select value from v$parameter where name = 'processes' --數(shù)據(jù)庫允許的最大連接數(shù)
修改最大連接數(shù):
alter system set processes = 300 scope = spfile;
重啟數(shù)據(jù)庫:
shutdown immediate;
startup;
--查看當(dāng)前有哪些用戶正在使用數(shù)據(jù)
SELECT osuser, a.username,cpu_time/executions/1000000||'s', sql_fulltext,machine
from v$session a, v$sqlarea b
where a.sql_address =b.address order by cpu_time/executions desc;
連接數(shù)配置在:applicationcontext.xml中
另一種解決辦法:直接用存儲過程,一個存儲過程只占一個連接。
查看當(dāng)前最大連接數(shù):
BasicDataSource dataSource = (BasicDataSource)SpringTools.getBean("dataSource");
System.out.println(dataSource.getNumActive());
posted on 2013-08-14 17:07 半導(dǎo)體 閱讀(297) 評論(0) 編輯 收藏 所屬分類: Eclipse