Hi
Thanks for replying
I wrote a package,the code is as below,it is working fine but the only issue is that every time there is a request a new factory is created.
I want to know how to create the factory only once and reuse the connections in the pool.
use ResourcePool;
use ResourcePool::Factory;
use ResourcePool::Factory::DBI;
$db_timeOut = 120; # wait 60 seconds for connection
#User credentials
$data_source = 'dbi:DB2:databasename';
$username = 'username';
$auth = 'password';
eval{
# set alarm to timeout current operation
local $SIG{ALRM} = \&input_timed_out;
alarm $db_timeOut;
$factory = ResourcePool::Factory::DBI->new($data_source,$user
+name,$auth);
$pool = ResourcePool->new($factory, Max => 2, MaxTry => 3, Sle
+epOnFail => [30, 60] ,MaxExecTry => 3);
};
alarm 0; # reset the alarm
sub resource_pool
{
$resource = $pool->get();
return $resource ;
}
sub release_pool
{
$pool->free($resource);
}
sub input_timed_out
{
print "connection timed out hence exiting\n";
exit;
}
|