I am trying to create a kind of scheduler, which works fine for simple tasks in a queue.
For Example:
If my queue has 100 jobs for 100 customers means 1 job for each customer.
But now I want to add multiple jobs for each customer.
for(int i = 1; i <= 100; i++) {
customerIds.add(i);
}
List<Job> jobs = new ArrayList<>();
for(Integer customerId: customerIds) {
for(int i = 1; i <= 10000; i++) {
jobs.add(new MyJob(customerId, 100));
}
}
Now I want to execute 1 job at a time for every customer instead of blocking the program to execute all jobs for 1 customer.
Can someone lead me in some direction? I am new to multithreading and not sure how can I make use of that here.
Also, the queue is not only for a predefined collection of jobs. It is kind of a stream where jobs will keep coming and gets executed.