将oracle-ds.xml 放到 jboss_home\server\default\deploy下
<?xml version="1.0" encoding="UTF-8"?> <datasources> <local-tx-datasource> <jndi-name>MYDS</jndi-name> <connection-url>jdbc:oracle:thin:@1.18.18.137:1522:NAME</connection-url> <driver-class>oracle.jdbc.driver.OracleDriver</driver-class> <user-name>dcx</user-name> <password>dcx</password> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name> <min-pool-size>10</min-pool-size> <max-pool-size>30</max-pool-size> <idle-timeout-minutes>5</idle-timeout-minutes> <metadata> <type-mapping>Oracle9i</type-mapping> </metadata> </local-tx-datasource> </datasources>
oracle jar放到 jboss_home\server\default\lib 下
java 代码 获得连接
import java.sql.SQLException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; public class DS { public static DataSource ds = null; public static java.sql.Connection getConnection() throws SQLException{ if(ds == null){ Context ctx; try { ctx = new InitialContext(); ds = (DataSource) ctx.lookup("java:MYDS"); } catch (NamingException e) { e.printStackTrace(); throw new RuntimeException("init data source error"); } } return ds.getConnection(); } }
查看运行时的连接池状态
http://localhost:8080/web-console/
System
--JMS MBeans
----jboss.jca
------jboss.jca:service=ManagedConnectionPool,name=MYDS
--------这下面有很多属性(如 ConnectionCount), 可以选中 右键 graph查看图示
!!!!
如果把jboss-common.jar 放到WEB-INF/lib 下, 最后被部署到jboss上,
会导致
ds = (DataSource) ctx.lookup("java:MYDS");
得到的ds == null, 所以不要这么做
!!!!
jboss scheduler docs
http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch10.html
http://hi.baidu.com/trstones/blog/item/b8f25416d43c9e49f2de32ac.html
写一个 实现 import org.jboss.varia.scheduler.Schedulable 的类
1. export the project's src to a jar file mysrc.jar
2. put the mysrc.jar, dependcy.jar in jboss_home/server/default/lib
3. put scheduler-service.xml in jboss_home/server/default/deploy
<mbean code="org.jboss.varia.scheduler.Scheduler"
name=":service=estoretestItem">
<attribute name="StartAtStartup">true</attribute>
<attribute name="SchedulableClass">com.lich.MySrcSchedulable</attribute>
<attribute name="SchedulableArguments">64039,64039,01</attribute> //传给构造器的参数
<attribute name="SchedulableArgumentTypes">java.lang.String,java.lang.String,java.lang.String</attribute> //参数类型
<attribute name="InitialStartDate">0</attribute> //开始时间 ,0是马上
<attribute name="SchedulePeriod">90000</attribute> //运行频率
<attribute name="InitialRepetitions">-1</attribute>
<attribute name="FixedRate">true</attribute>
</mbean>
scheduler 任务是server级别的, 和war是无关的