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
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|