我有一个应用程序,我正在使用DBCP连接机制和tomcat8。
<Resource
auth="Container"
driverClassName="oracle.jdbc.OracleDriver"
maxActive="5" maxIdle="1" maxWait="-1"
name="jdbc/XXX_DATASOURCE"
password="XXXXXX"
type="javax.sql.DataSource"
url="jdbc:oracle:thin:@host:1522:pos"
username="XXXX"
removeAbandoned="true"
removeAbandonedTimeout="60" logAbandoned="true"/>
它适用于任何getConnection
请求,但一种方法运行大约7到9次,然后在返回连接时卡住。
不知道如何调试,有人可以提供帮助。 把方法放在下面
public static String addInventoryForDealer(Order orderData, String status, String response)
{
response = "0";
List<Material> materialDataList = null;
Connection connection = DBCPContextListener.getConnection();
CallableStatement cs = null;
ResultSet rs = null;
String materialCode=null;
String tempMaterialcode;
DelegatingConnection del = new DelegatingConnection(connection);
OracleConnection conn = (OracleConnection) del.getInnermostDelegate();
StructDescriptor materialTypeDesc,materialSrNumTypeDesc,materialBundleTypeDesc;
try {
materialTypeDesc = StructDescriptor.createDescriptor("MATERIAL_BUNDLE_DETAIL",
conn);
materialSrNumTypeDesc = StructDescriptor.createDescriptor("MAT_SR_NO",
conn);
materialBundleTypeDesc = StructDescriptor.createDescriptor("MAT_BUNDLE_TYPE",
conn);
materialDataList = orderData.getMaterialDataList();
if(materialDataList != null && (!materialDataList.isEmpty()))
{
// array holding structs, where each struct is based on an array
// with fields of Project object
STRUCT[] materialAsStructs = new STRUCT[materialDataList.size()];
STRUCT unitSrNumberStruct = null;
// for each Project object, create a STRUCT object containing its fields
for (int i = 0; i < materialDataList.size(); ++i) {
Material material = materialDataList.get(i);
//create a pipe seperated string for all bundles
STRUCT[] BunitSrNumStructs = new STRUCT[material.getSerialNumberList().size()];
for(int j = 0; j < material.getSerialNumberList().size(); j++)
{
Object[] bundleFields = null;
//start JFT check if needed
BundleData bundleData = material.getSerialNumberList().get(j);
//create unit sr number structs
STRUCT[] unitSrNumStructs = null;
if(bundleData.getUnitSerialNumber()!= null && !bundleData.getUnitSerialNumber().isEmpty())
{
unitSrNumStructs = new STRUCT[bundleData.getUnitSerialNumber().size()];
for(int k = 0; k < bundleData.getUnitSerialNumber().size(); k++)
{
Object[] unitSrNoFields = new Object[]{bundleData.getUnitSerialNumber().get(k)};
unitSrNumberStruct = new STRUCT(materialSrNumTypeDesc,conn,unitSrNoFields);
unitSrNumStructs[k] = unitSrNumberStruct;
}
bundleFields = new Object[] {bundleData.getId(),unitSrNumStructs};
}
else
{
unitSrNumStructs = new STRUCT[1];
Object[] unitSrNoFields = new Object[]{bundleData.getId()};
unitSrNumberStruct = new STRUCT(materialSrNumTypeDesc,conn,unitSrNoFields);
unitSrNumStructs[0] = unitSrNumberStruct;
bundleFields = new Object[] {"",unitSrNumStructs};
}
//end JFT
//Object[] bundleFields = new Object[] {bundleData.getId(),unitSrNumStructs};
STRUCT materialBundleStruct = new STRUCT(materialBundleTypeDesc,conn,bundleFields);
BunitSrNumStructs[j] = materialBundleStruct;
// Object[] maertialSrBundleFields = new Object[] {bundleData};
// STRUCT materialBundleStruct = new STRUCT(materialBundleTypeDesc,conn,maertialSrBundleFields);
// materialBundleStructs[j] = materialBundleStruct;
}
//remove all zero
materialCode=material.getMaterialCode();
tempMaterialcode = materialCode;
//tempMaterialcode = StringUtils.stripStart(materialCode, "0");
System.out.println("material code"+tempMaterialcode);
Object[] maertialFields = new Object[]
{tempMaterialcode, BunitSrNumStructs, material.getSerialNumberList().size()};
STRUCT materialStruct = new STRUCT(materialTypeDesc,
conn, maertialFields);
materialAsStructs[i] = materialStruct;
}
// now you have all your Project objects ready to be saved in one go:
ArrayDescriptor maertialTypeArrayDesc = ArrayDescriptor.createDescriptor
("MATERTAIL_DETAIL_TABLE", conn);
ARRAY arrayOfmaterials = new ARRAY(maertialTypeArrayDesc, conn,
materialAsStructs);
System.out.println("orderNumber:"+orderData.getOrderNumber());
cs = conn.prepareCall("{call PROC_UPDATEINVENTORY(?,?,?,?,?,?)}");
cs.setString(1, orderData.getOrderRefernceNumber());
cs.setString(2, status);//TODO decide status on bases of goods issued and received
logger.debug("status"+status);
cs.setArray(3, arrayOfmaterials);
logger.debug("array:"+Arrays.asList(arrayOfmaterials));
cs.setString(4, "0");
cs.registerOutParameter(5, Types.DECIMAL); //error code
cs.registerOutParameter(6, Types.VARCHAR); //error msg
cs.execute();
materialDataList=null;
//fill material type and count only not material details
rs = cs.getResultSet();
//System.out.println(rs.getDouble(5));
//System.out.println(rs.getString(6));
if(cs.getInt(5) == 0)
{
response = "SUCCESS";
/* while(rs.next())
{
response = cs.getString(10);
//material count and status for the dealer
Material temp = new Material();
materialDataList.add(temp);
}
orderDetail = new Order();
orderDetail.setMaterialDataList(materialDataList);
*/
}
else
{
response = "FAILED";
}
}
}
catch(SQLException sqle){
logger.error("Exception Ocurred - " + sqle.getMessage(), sqle);
try {
conn.rollback();
} catch (SQLException e) {
logger.error("Exception Ocurred - " + e.getMessage(), e);
}
response= "FAILED";
}
catch(Exception e)
{
logger.error("Exception Ocurred - " + e.getMessage(), e);
response="FAILED";
}
finally{
DBAccess.closeResources(conn, cs, rs);//TODO no parameter to pass for callable statement
}
return response;
}