title: Create new thread in for loop inside public void method()
body: <p>I have a class that ping IP addresses. To start ping I have public vod run() method to start pinging. Problem is that I want ping more IP addresses at same time (for each IP address I need new Thread). So how can I create new Thread inside for loop. Here is code of my ping class:</p>
  
  <pre><code>public void run()
      {
      if (dbConnection.ConnectToDB())
      {           
          for (;GateWayKey&lt;=GateWayKeyStop;GateWayKey++)
          {
              if(stop || this.isInterrupted()){
                  return;
              }
              ip="192.168."+GateWayKey+".1";
              InetAddress address;
              try {
                  address = InetAddress.getByName(ip);
                  try {
  
                      if (address.isReachable(PingTime))
                      {
  
                          //System.out.println("Pronaden GateWay: "+ip)
                      //  labele.IP
                          sql="INSERT INTO `iptables` (`IP` , `COMPUTER_NAME` , `GATEWAY_KEY`) VALUES ('"+ip+"', '"+address.getHostName().toString()+"', '"+GateWayKey+"');";
  
  
                          framedocs.WriteMonitorData (ip, address.getHostName().toString(),"2000","DA",dbConnection.WriteToDB(sql));
                          for (;SubNetKey&lt;=SubNetKeyStop;SubNetKey++)
                          {
                              if(stop || this.isInterrupted()){
                              return;
                              }
                              InetAddress addressIps = InetAddress.getByName("192.168."+GateWayKey+"."+SubNetKey);
                              System.out.println("Provjeravam IP: "+addressIps);
                              if (addressIps.isReachable(PingTime))
                              {
                                  ip="192.168."+GateWayKey+"."+SubNetKey;
                                  System.out.println("Pronaden IP: "+ip);
                                  sql="INSERT INTO `iptables` (`IP` , `COMPUTER_NAME` , `GATEWAY_KEY`) VALUES ('"+ip+"', '"+addressIps.getHostName().toString()+"', '"+GateWayKey+"');";
                                  framedocs.WriteMonitorData (ip, address.getHostName().toString(),"2000","DA",dbConnection.WriteToDB(sql));                          
                              }
                              else
                              {
                                  framedocs.WriteMonitorData (addressIps.toString(), "N/A","2000","NE","N/A");
                              }
  
                          }
                      }
                      else
                      {
                              framedocs.WriteMonitorData (ip, "N/A","2000","NE","N/A");
                      }
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      framedocs.WriteMonitorData (ip, "N/A","2000",e.getMessage(),"N/A");
                  }
              } catch (UnknownHostException e) {
                  // TODO Auto-generated catch block
                  ;
                  framedocs.WriteMonitorData (ip, "N/A","2000",e.getMessage(),"N/A");
              }
          }
  
      }
      else
      {
          framedocs.WriteMonitorData ("MySQL error", "N/A","N/A","N/A","N/A");
      }
  </code></pre>
  
  <p>}</p>