#
關于如何配置Tomcat數據庫連接池,網上已有太多文章了。可是找不到一篇文章能
告訴我,怎么能得到Tomcat連接池的當前連接數。如果想要監視Tomcat的運行狀況,這
是一個重要參數。所以我花了半天的時間,專門來研究這個問題。
先是看了Tomcat的相關源碼,得到它用了jakarta commons-dbcp這個包,又下載了
commons-dbcp這個包的源嗎。終于在BasicDataSource找到getNumActive方法,這就是我想
要的。
Context initCtx = new InitialContext();
BasicDataSource bds = (BasicDataSource)initCtx.lookup("java:comp/env/jdbc/afunms");
initCtx.close();
bds.getConnection();
System.out.println("當前連接數=" + bds.getNumActive());
隨時getConnection()的增加,這個numActive也會增多(如果不關閉connection的話)。
當numActive>maxActive(這個maxActive在xml文件中)時,程序就再不能連上DB了。這就
是我以前的程序為什么會出錯的原因,哈哈。
注:在連接池配置文件.xml中要寫明
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
從《Port分配》里導出三個表:PL_UNIT、PL_ATM、PL_ATM_PORT。
ATM交換機在每個單位都有一臺,其實可以把PL_UNIT、PL_ATM兩表合一,但后來考慮到以后還有其他的設備比如路由和視頻都要加入,它們也得和單位相關聯,所以把單位信息單獨拿出,放到一張表里。
表PL_UNIT:
字段
|
屬性
|
說明
|
備注
|
ID
|
NUMBER(3)
|
ID
|
|
UNIT
|
VARCHAR(30)
|
單位信息
|
|
表PL_ATM:
字段
|
屬性
|
說明
|
備注
|
ID
|
NUMBER(3)
|
ID
|
|
UNIT_ID
|
NUMBER(3)
|
單位ID
|
PL_UNIT.ID
|
ATM
|
VARCHAR(30)
|
ATM機器名
|
|
IP
|
VARCHAR(15)
|
IP地址
|
|
表PL_ATM_PORT:
字段
|
屬性
|
說明
|
備注
|
ID
|
NUMBER(3)
|
ID
|
|
ATM_ID
|
NUMBER(3)
|
ATM交換機ID
|
PL_ATM.ID
|
SLOT
|
NUMBER(3)
|
板卡
|
|
PORT
|
NUMBER(3)
|
端口
|
|
DESCRIPTION
|
VARCHAR(30)
|
端口描述
|
|
表TOPO_HOST_NODE與PL_ATM有重復的數據,但沒辦法,因為前者的數據為拓撲自動發現的,而后者的數據是從Excel文件中導入的,二者數據不可能完全一致,所以只能保留兩個表。而PL_ATM表中的IP地址是從表TOPO_HOST_NODE查詢得到的。因為在Excel文件,沒有任何ATM與IP對應的信息,我只能從發現的結果中查詢得到各機器的IP地址。
從《PVC規劃和配置》中導入ATM PVC數據,我覺得這些數據應該與PL_UNIT關聯,但由于《PVC規劃和配置》中單位名稱與《Port分配》中的單位名稱不一致,所以關聯起來有困難,就是要人為一個個去找。暈,暫時先這樣吧,給用戶看過后再說吧。
(1)CVS提交或更新的時候老是出現一個錯誤:
cvs server: C:\WINDOWS\TEMP\cvsC7.tmp: No such file or directory
cvs [server aborted]: error diffing test.txt
根據網上資料提示,覺得可能是以下原因:
1.CVSROOT下的Reposity下的路徑設置不真確.
2.可能該用戶沒有設置該權限.
一一排查,最后才發現是因為CVSNT服務器上運行的賬號是USER用戶組的,沒有對C:\WINDOWS操作權限
,因此我更改CVSNET臨時目錄,從c:\windows\temp到d:\cvs_temp,再運行提交,問題解決。
(2)第一次用正則表達式。
以前一直認為正則表達式是很神秘的東西,今天努力試用一下,才知道其實很簡單。
我要從“Switch code: GDFY1P45”找出ATM的機器名“GDFY1P45”,
因為機器名總是xxxx1P(或G)dd,所以我寫一個正則表達式來匹配它
Pattern aliasPattern = Pattern.compile("[1]{1}(P|G){1}[1-9]{1,2}");
很容易就找出機器名了,呵呵。
要從GDFY1P45_s5p7-GDFY_MON_SP找出_后的s5p7-GDFY_MON_SP
Pattern portPattern = Pattern.compile("[_]{1}[s][0-9]{1}[p][0-9]{1}[-]{1}");
感覺很爽。
** Version 1.3.2.Alpha, Release Date 2007.09.18
* Serious Bug:add a new node dynamically at runtime,the polling thread
doesn't query it.The involved classes are TopoResourcePool.java and
PollingEngine.java.
1. 用XmlHttp獲取xml,responseXml為空。
解決方法:
在web.xml中加入
<mime-mapping>
<extension>xml</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsl</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
2. 用SmartUpload下載文件時出錯
出錯信息:
java.io.IOException: 文件名、目錄名或卷標語法不正確。
at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:395)
at java.io.File.getCanonicalPath(File.java:531)
at weblogic.servlet.internal.WebAppServletContext.getRealPath
(WebAppServletContext.java:666)
at com.jspsmart.upload.SmartUpload.isVirtual(SmartUpload.java:1180)
Truncated. see log file for complete stacktrace
解決方法:自己寫了一個Servlet來下載文件,代碼如下:
1
public class DownLoad extends HttpServlet
2

{
3
private static final long serialVersionUID = -84138329260803824L;
4
public void init() throws ServletException
5
{
6
}
7
8
public void doGet(HttpServletRequest request, HttpServletResponse response)
9
throws ServletException, IOException
10
{
11
OutputStream os = null;
12
FileInputStream fis = null;
13
try
14
{
15
String fileName = request.getParameter("filename"); //要下載的文件,包括路徑
16
String downFileName = fileName.substring(fileName.lastIndexOf("\\") + 1); //去掉路徑
17
18
os = response.getOutputStream();
19
File f = new File(fileName);
20
21
response.setHeader("Content-type:", "application/octet-stream");
22
response.setHeader("Accept-Ranges:", "bytes");
23
response.setHeader("Accept-Length:", Long.toString(f.length()));
24
response.setHeader("Content-Disposition", "attachment; filename=" + downFileName);
25
26
fis = new FileInputStream(f);
27
byte[] b = new byte[1024];
28
int i = 0;
29
while((i = fis.read(b)) > 0)
30
os.write(b, 0 ,i);
31
}
32
catch (Exception e)
33
{
34
e.printStackTrace();
35
}
36
finally
37
{
38
fis.close();
39
os.flush();
40
os.close();
41
}
42
}
43
44
public void doPost(HttpServletRequest request, HttpServletResponse response)
45
throws ServletException, IOException
46
{
47
doGet(request,response);
48
}
49
}
這周末全公司組織出去旅游,大家都玩得很開心。
昨天去漂流,今早騎馬,然后泡溫泉。
1. December,2007: Add distributed feature to SourceView1.0
with JMX.
2. February,2008: Refactor SourceView,update to version2.0.
The new version must have three features:
a. MVC
b. NMS
c. Distributed.
3. June,2008: A new product,NetFlow.
1. Replaced Ping by SnmpPing.(ResponseTime.collectData())
2. Started to remove GDPLN project from Tomcat to Weblogic.
3. Massive data will be created in future,so we choose Oracle instead of MySQL.
Combine Weblogic with Oracle,we can build a more powerful system.
昨日給用戶演示了我們的軟件,他們對我們的軟件表示認可。至少是相信,
我們能很好地完成這個項目。
工作近四年,回顧一下,自己的代碼在哪些單位的服務器上跑著:
1. 山東濟南將軍集團 (2004.06)
2. 遼寧遼寧電力 (2004.10)
3. 遼寧沈陽供電局 (2005.02)
4. 河北秦皇島港務局(2005.06)
5. 山東齊魯石化 (2006.11)
6. 河北衡水信用社 (2007.04)
7. 安徽恒源煤電 (2007.06)
8. 廣東PLN (2007.09)
昨天完成有關PVC的所有程序,今天上午調試通過,包括與ITSM的接口程序。
今天讓XUE先看一下,他表示基本滿意,算是一個階段性的勝利吧。
明天給用戶演示一下,根據他們的意見,再作進一步的工作安排。
至于物理鏈路,我想一定也能在mib中找到,只是,目前來說,我對atm還不夠了解。
1. Tested SourceView1.3.1.Alpha,that is ok.
-------GDPLN---------
2. Ignored ATM switches' interfaces,because they are insignificant.
(DiscoverEngine.addHost())
3. ATM switches' interfaces are ignored,so deleted those traffic monitors for them.
(monitors.xml)
4. Modified ip resource module,two factors contribute to this,
added a new feature about PVC and deleted the feature about VLAN.
5. Added a new class LucentTypeHelper to convert type digit to the description
accordingly.
6. Fetchs PVC information through another SNMP table intfAtmPvcConnDisplayTable,
instead of ipAtmAppPvcVccStatsTable,simplified the relative program consequently.
7. Created a new db table NMS_ATM_PVC,which stores PVC data.
8. Added two device categories,5=Lucent ATM switch,6=Keda video.
--------SourceView-----------
** Version 1.3.1.Alpha, Release Date 2007.09.11
* Modifiy: Sometimes the bridgeAddress of switch(or router) can not be got,
thereby fetching again before this node is added to the nodes list.
(DiscoverEngine.addHost())
* Modifiy: SnmpWalk operation.(SnmpService.snmpWalk())
* Modifiy: Vlan-interface mapping,affected by modification of SnmpWalk
operation(ExtendSnmpUtil.getVlanIfMap()).
* Add: Printing out the debug information when it is needed.
(SysProperty.isLogDebug())
--------GDPLN------------
1.完成有關“板卡、接口和通道”的程序。
2.找到完整的PVC信息,包括PVC兩端的設備、接口和通道。
今天寫一些Lucent ATM相關程序,明天拿到GDPLN去測試一下。
現在我對這個項目越來越有信心了。
看了一天jmx的相關文檔,還是云里霧里。暈啊
不過,我已經決心要多研究開源代碼,然后,做一個更好的架構,以實現分布式網管。
** Version 1.3.0.Alpha, Release Date 2007.09.07
* Add: SQL-Server monitor.
* Add: Algorithm for topology display.
* Modifiy: loads the monitor class when it is needed,rather than loads all classes at the beginning.