Question

I am new to threading and have very less knowledge in Java I am facing some serious performance issues with my data insertion in mysql. Data is huge chunk and takes huge amount of time, even when done with batch, prepared statement.

I want to read keys and values from hashtable and divide particular say-5 indexes that are to be inserted in mysql table using threads. Which I assume would boost up my performance. Suppose there are 100 index; so I want to create 5 threads, individual of which inserts 20 values in database. I can create a thread array and pass them executor pool and submit, but I am stuck how to proceed there after.

I have following doubts: how do I keep track of thread how much it has inserted or how do I limit the thread for 20 insertion? Can I further divide work of 20 insertion by each thread into batch of 4?

I am not looking for code, but right guidance which might help.

Was it helpful?

Solution

I would, personally, use the Executor API.

Basically, I would create a fixed pooled executor and simply submit the tasks you want to execute to it and allow it to manage the pool of tasks as an existing thread becomes available.

Take a look at Executors tutorial for more details

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top