If I understand correctly, you have some tasks that must be performed sequentially (I assume 10) for each entry of the array.
First, you need to organize this 10 tasks sequentially, in a class that implements Runnable
:
public class ThreadedTask implements Runnable {
private Employee employee;
public ThreadedWork(Employee employee) {
this.employee = employee;
}
public void executeTaskList(Employee employee) {
task1(employee);
task2(employee);
// ...
task10(employee);
}
public void run() {
executeTaskList();
notify();
}
}
Then, you can implement one of this solutions:
- Insert the
Employee
object in the array, create a ThreadedTask
object and call its execution on a thread.
- Insert all the
Employee
objects in the array, and then use a for
loop to create a ThreadedTask
object and call its execution on a thread.
I'll write here a simple proposal for option 2:
/*
* I am assuming that there`s an array called empArray, which holds 100 employees.
* It's up to you to decide how it is populated.
*/
public void processEmployees() {
// ...
for(Employee e : empArray) {
(new Thread(new ThreadedTask(e))).start()
}
// ...
}
As you see, the logic is split in two: It's up to you to define the way empArray
is populated, and how the ThreadedTask
object is created and executed. But the ThreadedTask
executes the task list sequentially for every Employee
object.
Notice that there's no way to tell which Employee
object is processed on any given moment. All the employees are processed concurrently, but the tasks for each employee are executed sequentially.
Hope this helps