Results 1 to 6 of 6

Thread: Multithreading and ArrayList

  1. #1
    Join Date
    Dec 2009
    Posts
    211

    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.

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    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.

  3. #3
    Join Date
    Dec 2009
    Posts
    211

    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]
    }());
    				}

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    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]
    }());
    	}
    }

  5. #5
    Join Date
    Dec 2009
    Posts
    211

    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.

  6. #6
    Join Date
    Nov 2009
    Posts
    333

    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.

Similar Threads

  1. Multithreading in intel IPP
    By Assasin boy in forum Motherboard Processor & RAM
    Replies: 9
    Last Post: 26-09-2010, 03:25 AM
  2. run method of MultiThreading
    By beelow in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 10:18 AM
  3. How to achieve Multithreading in Java
    By LasitMalinga in forum Software Development
    Replies: 3
    Last Post: 02-05-2009, 01:09 PM
  4. Problem with Multithreading in C Language
    By Jagdish Gada in forum Software Development
    Replies: 4
    Last Post: 09-03-2009, 02:10 PM
  5. forks and multithreading
    By invincibledj20 in forum Software Development
    Replies: 0
    Last Post: 12-11-2008, 07:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,820,230.98478 seconds with 16 queries