Multithreading and ArrayList
Hello,
I applied a small network or I find myself with a large quantity of objects. I made after a ping I find myself with about 1,000 IP addresses that are objects and that I would put in a collection but which one? Knowing that soon (not now I don t have time) I want to make multithreaded I think this is of use preferable Hashtable because I've started but with Vector, but it seems inadvisable because old and overused. I want to use multithreading with ArrayList, is this possible to do. If you have any solution for this, then please help me. I am interested in this.
Re: Multithreading and ArrayList
Hello,
A Map (as Hashtable) is used to quickly access an object accurate a collection. If this is not your need, an ArrayList is sufficient. You will be able to synchronize with multithreading Collections.synchronizedList (..). I think you should go with this and I think you do not need multitasking for this. Still, if you use it, it is going to be tough for you to code for that.
Re: Multithreading and ArrayList
Hello,
This is my code, see it and if you find any problems in it then correct me and guide me to the correct code.
Code:
Public void lancerScan(){
String str = null;
try
{
str = "Executable\\test.exe "+???????+"H-Temp\\Ping.txt ";
Runtime rntm = isp.getRuntime();
Process = isp launch.exec(str);/ / start of command
launch.waitfor();/ / wait for the command is //finished to start another
}
catch(Exception e)
{
System.out.System.out.println("rntm error" + Cmd[i] + E.function toString() {
[native code]
}());
}
Re: Multithreading and ArrayList
Hello,
I have modified your code, just go through it and then see if it works, for me it works here, but your needs may be different.
Code:
Public void uneMéthodeAppelante(){
List lp = ....;
.......
for(int i =0; I <lp.size(); i + +)
{
lancerScan(lp.get(i));
}
}
Public void lancerScan(String ip){
String str = null;
try
{
str = "Executable\\test.exe "ip + +"H-Temp\\Ping.txt ";
Runtime runtime = isp.getRuntime();
Process = isp launch.exec(str);/ / start of command
launch.waitfor();/ / wait for the command is finished to start another
}
catch(Exception e)
{
System.out.System.out.println("runtime error" + Cmd[i] + E.function toString() {
[native code]
}());
}
}
Re: Multithreading and ArrayList
Hello,
I did it like this to start the method and it works perfectly
Code:
{for(String e: ipls)
ip.lancerScan(e);
}
I am now trying to do the same thing by sending two things just like below but it does not work.
Code:
{for(String e: ipList, String f: getNameNetworks())
ip.lancerScan(e, f);
}
If you know thank you very much knowing getNameNetworks returns a list
I continue my tests.
Re: Multithreading and ArrayList
Hello,
I think using the following code you can get good performance by your code. Just have a look at it.
Here is the code
Code:
{
for( Strinf f: getNameNetworks() )
{
for(String e: ipList)
{
ip.lancerScan(e, f);
}
}
}
By using the following code I think you can get a better performance from your program , I mean to say that your code will work much faster.