1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| public class totothread extends Thread
{
int range1, range2;
ArrayList<Object> trucsatraiter;
public totothread(int range1, int range2, ArrayList<Object> trucsatraiter)
{
//...
}
public void run()
{
for (int i = range1; i < range2; i++)
{
Object o = trucsatraiter.get(i);
// Fait un truc avec cet objet.
}
}
public static void main(String args[])
{
ArrayList<Object> trucsatraiter = null; // Ici il remplir une liste d'objet a traiter. (20 par exemple)
//...
totothread t1 = new totothread(0, 10, trucsatraiter);
totothread t2 = new totothread(11, 20, trucsatraiter);
t1.start();
t2.start();
t1.join();
t2.join();
}
} |
Partager