package com.jiuqi.mobile.core.service.service;
import java.sql.Connection;
import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import com.jqmobile.core.orm.IDBPool;
import com.jqmobile.core.orm.ORM;
import com.jqmobile.core.orm.exception.ORMException;
import com.jqmobile.core.orm.exception.ORMNotDBTableException;
import com.jqmobile.core.server.db.DBPool;
import com.jqmobile.core.server.db.orm.ORMFactory;
import com.jqmobile.core.utils.thread.AsyncTask;
public class TestDBPool extends Assert{
private final static String string = "select count(recid) from TEST_TIME";
// private static int time=0;
public void testPool(){
final DBPool pool = DBPool.getInstance();
for(int i=0; i<1000; i++){
AsyncTask<IDBPool, Connection> task = new AsyncTask<IDBPool, Connection>(){
@Override
protected Connection doInBackground(IDBPool... params)
throws Throwable {
return params[0].getConnection();
}
@Override
protected void onPostExecute(Connection result) {
System.gc();
try {
ORM<CountBean> orm = ORMFactory.instance(result,CountBean.class);
int l = orm.queryRow(null, null);
} catch (ORMNotDBTableException e) {
e.printStackTrace();
} catch (ORMException e) {
e.printStackTrace();
}finally{
try {
result.commit();
result.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
// try{
// try {
// // System.out.println(l);
// // if(time%100==0)
// // System.out.println("==========================================:\t"+time++);
// PreparedStatement ps = result.prepareStatement(string);
// ps.execute();
//// ResultSet rs = ps.executeQuery();
//// if(rs.next()){
//// System.out.println(rs.getInt(1));
//// }
//// rs.close();
// ps.close();
// result.commit();
// // result.close();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }finally{
// try {
// result.close();
// System.out.println(result);
// } catch (SQLException e) {
// e.printStackTrace();
// }
// }
}
};
task.execute(pool);
}
while(true){
try {
Thread.sleep(3000);
System.out.println("=============================thread count:\t"+AsyncTask.getThreadCount());
System.out.println("=============================task count:\t"+AsyncTask.getTaskCount());
// System.out.println("=============================wcount:\t"+wcount);
// System.out.println("=============================ecount:\t"+ecount);
if(0 == AsyncTask.getThreadCount()){
// testTime();
return;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}