主要支援了最新的Java EE 6規格裡的:
- Servlet 3.0
- JSP 2.2
- EL 2.2
按這裡下載
另外,Java EE 6 Tutorial文件 按這裡 可以找到~
故事是這樣的:
我的程式直接使用MySQL connector/J JDBC Driver連接資料庫操作都很正常 ,
但透過Tomcat配置的data source(DBCP)取得connection來對資料庫操作 ,
總是不定時的會出現 'No operation allowed after connection closed' 錯誤訊息,
意思是connection已經被關閉掉了,
也換了最新的JDBC Driver, 也換過Tomcat 版本,怎麼試結果都一樣,還是錯,
查了許久也作了trace, 這connection並不是我的程式關掉的,
同時還將程式移到了websphere 並使用websphere中的connection pool, 結果是不會發生這樣的錯誤的。
那麼剩下的兩個可能便是:
OK, 網上拜神(Google), 搜到許多的線索, 有人說connection url要有autoReconnect=true選項,但這僅適用於連線時間超過八小時者。bug database有類似問提,但早就已經修正好了。 也有人說要改MySQL server的my.ini (my.cnf) ,恩...改了可是還是錯。
OK...上面都是廢言....
解決方案是在 tomcat server.xml中的<context>其內的<resource>標籤(設定DataSource用的)要多一個 屬性 validationQuery="select 1" , 之後便不會再三不五時拿到被關掉的connection了,測底解決。
----------------------------------------------------------------------------------------------
為何如此能解決呢??
我猜想大概是多了validationQuery後, DBCP在做相關資料庫操作時,
若該connection沒被客戶端程式(也就是我的程式)手動關閉connection ,也沒被DBCP關閉connection ,
會先用validationQuery的sql檢查, 是否連線被MySQL server端中斷了 ,如果是就自動再從MySQL server取得一個新的connection。
以上僅是小弟猜測, 因為對DBCP內部運作並不是很熟悉 ,所以如有人能回答請不吝提供正確答案...
-------------------------------------------------------------------------------------------
但... 問題來了....
如果以上我的猜測是正確的..... 那麼DBCP自動從MySQL server再次取得新的connection , 那麼也就代表了我之前被MySQL server端無端close掉的connection若是transaction的(autoCommit=false)不就無端的被中斷掉了,而且我也不會得知..... +.+ \\\
,這樣實在太太太不合理的.....................
所以說呢無端斷線問題暫時解決, 但關於transaction的疑問, 不知有哪位先進可以回答呢??
# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.misfireThreshold = 60000
# org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.CloudscapeDelegate
org.quartz.jobstore.dataSource = MailerJ
org.quartz.jobStore.useProperties = true
org.quartz.dataSource.MailerJ.jndiURL = java:comp/env/jdbc/JMailer
org.quartz.jobStore.dataSource = MailerJ
在Tomcat上跑JSP常寫些custom tag lib如下:<myLib:myTag attribute1=" <%=request.getParameter("param") %> " />但在OC4J竟然會解析錯誤,無法解譯成java檔。
這真是令我想不透。
經過一番追查,改成如下:<myLib:myTag attribute1=' <%=request.getParameter("param") %> ' />
竟然就可以了。
都是雙引號在作怪。
<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->
<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->
<!-- maxWait: Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<!-- username and password: MySQL dB username and password for dB connections -->
<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->
<!-- url: The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
</context>
其中注意兩個參數:
親身經歷的事--在連線數使用超過maxActive時,後面取得Connection都為null,導致無法取得資料,造成程式錯誤!