Requirement: Need to connect to multiple database and host remotely, get the data back and write into text file.
Approach : Thinking to use threads. Create thread pool of 20 threads and connect simultaneously and get data back. at present i am stuck, not able to ensure that how to get connection handle for each host/data server using threads.
Would be grateful if you can point me in right direction.
Thanks
example:
use strict;
use threads;
use Data::Dumper;
use threads::shared;
#number of service threads to create
my $threads = 20;
my %dataEntity = ('TEST' => "usr:passwd",
'TEST' => "usr:passwd"
);
# create a pool of three service threads
foreach (1.. $threads) {
threads->create(\&getData);
}
##
foreach my $dataServer (keys %dataEntity){
##not sure how will i use thread here
}
sub getData {
my $self = threads->self;
my $thread_line;
##how
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.