连接失效导致进程卡死。 过好久才能入库成功或者捕获异常,请问有什么办法能解决问题
这个是创建连接池代码
bool OraConnPool::createConnPool(const std::string& username, const std::string& passwd, const std::string& connectString, int maxCon, int minCon, int incrCon)
{
this->username = username;
this->password = passwd;
this->connstring = connectString;
this->maxCon = maxCon;
this->minCon = minCon;
this->incrCon = incrCon;
setenv("NLS_LANG", "SIMPLIFIED CHINESE_CHINA.ZHS32GB18030", 1);
//setenv("NLS_LANG", "american_america.AL32UTF8", 1);
sErrInfo=""; try
{
//env = Environment::createEnvironment(Environment::DEFAULT);
env = Environment::createEnvironment(Environment::Mode(Environment::OBJECT|Environment::THREADED_MUTEXED));
if (env == NULL)
{
sErrInfo="CreateConnpool Error!";
return false;
}
scp = env->createStatelessConnectionPool(username.c_str(), passwd.c_str(), connectString.c_str(), maxCon, minCon, incrCon, StatelessConnectionPool::HOMOGENEOUS);
scp ->setTimeOut(10000);
if (scp == NULL)
{
Environment::terminateEnvironment(env);
sErrInfo="Connection oracle error!";
return false;
} sErrInfo="CreateConnpool success! ";
return true;
}
catch(SQLException ex)
{
sErrInfo=ex.getMessage().c_str();
}
return false;
}这是获取连接代码Connection* OraConnPool::getConnection()
{
Connection * pConn = NULL;
pConn = scp->getConnection();

return pConn;
}
这个是class
class OraConnPool
{
protected:
OraConnPool();

public:
bool createConnPool(const std::string& username, const std::string& passwd, const std::string& connectString, int maxCon, int minCon, int incrCon);
bool reCreateConnPool();
void destroyConnPool();
string getErrData(void);

Connection * getConnection();
void freeConnection(Connection*);

static OraConnPool* getInstance();
bool checkConnect();
~OraConnPool();
private:
Environment * env;
StatelessConnectionPool * scp;
string sErrInfo;
static OraConnPool* _instance;
std::string username;
std::string password;
std::string connstring;
 int maxCon;
 int minCon;
 int incrCon;
};