i am trying to write a java programm that is reading informations out of a database and creates for every row of the table a new thread. So i dont know how much threads i will need. so far i have this:
con = DriverManager.getConnection(url, user, passwd);
pst = con.prepareStatement("select hostname, ipadress, vncpassword from infoscreens");
rs = pst.executeQuery();
int i=0;
while (rs.next()) {
i++;
Thread tread[i] = new Savescreenshots(rs.getString(1),rs.getString(3),rs.getString(2));
tread[i].start();
}
but the problem is that this isnt working. i need a possibility to create for each row in the table a new thread. dose anyone have an idea how to do that
thanks and greetings
You need a dynamically growing container for a set of unknown size – a
List, for example:At this point, all
Threadobjects that your program created and started are elements of thethreadslist. You can enumerate them and do whatever else you were planning to do with them (e.g. wait for them to finish):