Manpreet Singh

Greenhorn
+ Follow
since Oct 13, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Manpreet Singh

How can I pass number as command line arguments and that many numbers of threads will be created?

For this you would have to change the approach a little bit

In the main method -
1) Read the command-ling arguments (Say numberOfThreads)

2) Modify DataManagerThread

public class DataManagerThread extends Thread {

private Vector currentURLVector = null;

public DataManagerThread(Vector urllist){
//Create object of URLReader.
// Create Vector Array (Vector[] urllistArr) where -
a) size = urllist.size()/numberOfThreads + urllist.size)%numberOfThreads
b) Populate this Vector Array from urllist
}

public void execute(){
//Iterate thru the Vector[] urllistArr and call start() for each element.
DataManagerThread t = new DataManagerThread();
t.currentURLVector = urllistArr["Current Index"];
t.start();
}

public void run(){
//Iterate between URL's in t.currentURLVector
// call URLReader.execute(for each URL)
}
}

Hope this helps !!
You need to modify your DataManager class in a Thred !! e.g.

public class DataManagerThread extends Thread {

private String currentURL = "";

public DataManagerThread(Vector urllist){
//Create object of URLReader.
}

public void execute(){
//Iterate thru the Vector and call start() for each element.
DataManagerThread t = new DataManagerThread();
t.currentURL = "Current URL from Vector"
t.start();
}

public void run(){
// call URLReader.execute(t.currentURL)
}
}

P.S. Before instantiating these threads, you must check whether the URLs (in the Vector urllist) are unique,
so that you don't end up in a deadlock situation (Two threads reading the same resource )