user2691659
user2691659

Reputation:

Make Threads Per List Item

I am new to Java Concurrency and not really comfortable with examples provided by the docs. What i am trying to do is, I have a database of employers which i retrieve their credentials from the database and store it in java.util.list. I want to perform independent actions of each employee stored in the list concurrently. Is Multi-Threading the right direction ? and could i be guided with some pseudo example ?

N:B If my question is vague, comment so i may improve it rather than downvote.It's important i understand how i could accomplish this. Thanks

Upvotes: 0

Views: 108

Answers (1)

MightyPork
MightyPork

Reputation: 18881

Multi-threading, unless your task is very time consuming, is overkill. Especially if the list is large, making a thread for every single item is likely to be slower than just iterating over the list and doing it one-at-a-time.

More useful would be to divide the list into several chunks and process those in parallel.

Anyway, if you insist on using threads, you might make some use of ExecutorService.

Upvotes: 1

Related Questions