
amit1987
Novice
Jun 15, 2010, 1:23 AM
Post #1 of 1
(1015 views)
|
Use separate DB connection on Threads problem
|
Can't Post
|
|
Hi, I am facing some weird problem while fetching data from DB. I am creating separate DB connection for each thread and closing within same thread but when i run this code. MY FIRST THREAD GIVES PROPER RESULT (DISPLAYING ARGS AND RESPECTIVE VALUES ) BUT LATER ON (THREAD 2, 3 ) ... ITS NOT PRNTING VALUES: even though elements are present in that table !!
sub Indexing { #&dbconnect1; print "\nIn thread"; my $DBH1 = DBI->connect ( "dbi:Oracle:host=$DB_IP;port=$DB_PORT;sid=$DB_SID",$DB_USER,$DB_PWD) or die("ERROR;Can not Connnect with Database; command Terminated"); my @InboundParameters = @_; print "\n1:",$InboundParameters[0]; print "\n2:",$InboundParameters[1]; print "\n"; my $select =""; $select = qq/select INDEX_NAME from user_indexes where rownum between $InboundParameters[0] and $InboundParameters[1]/; my $selectprep =""; $selectprep = $DBH1->prepare($select); print "statement prepared !!! "; $selectprep->execute(); print "statement executed !!! "; my @row1=""; while (@row1 = $selectprep->fetchrow_array) { #print join(", ", @row), "\n"; print "\n ROW is : ",@row1; } print "Check output !!! "; $selectprep->finish(); print "Finished !!! "; $DBH1->disconnect(); #&dbdisconnect; } I am Calling it using ::
$T1 = threads->new(\&Indexing,0,50); print "\nWaiting for thread1 now"; $T1->join(); $T2 = threads->new(\&Indexing,51,100); print "\nWaiting for thread2 now"; $T2->join(); $T3 = threads->new(\&Indexing,101,150); print "\nWaiting for thread3 now"; $T3->join(); output :
In thread 1:0 2:50 statement prepared !!! statement executed !!! ROW is : IR1 ROW is : Ir2 ROW is : ir3 ROW is : IR4 ..... Check output !!! Finished !!! In thread 1:51 2:100 statement prepared !!! statement executed !!!EXPECTED OUTPUT NOT PRINTED Check output !!! Finished !!! statement prepared !!! ..... In thread 1:101 2:150 statement prepared !!! statement executed !!! Check output !!! Finished !!! statement prepared !!! Any help will be appreciated. Thank you
(This post was edited by amit1987 on Jun 15, 2010, 1:25 AM)
|