multithreading - handling multiple threads in java to send request and get response, to a C server application -


i have traditional problem that's living in java development years, couldn't decide best way of doing it. need advice pick best one. issue goes below -

client - java program (basically web based application)

server - written in c

requirement - user upload file may contain million records or example 50000 records. each record (line) have serial id, product name , customer name. java program should read file , send request c application on network. c server application respond request id , in java (client) need store request id in list that's synchronized , should query c server application find out status of request id sent earlier. , server responds either wip (work in progress) or done (completed) request id. if c server application response = done, server send data along response , if wip, client should retry 3 times interval of 5 seconds.

code design -

step 1 - read file line line

step 2 - after reading line, start thread send request server , stores response synchronized array list.

step 3 - thread read synchronized list , starts querying request status , stores final response c server app.

this might create memory overhead can see if file contains 100000 records, might create 100000 threads. can guys suggest me better way of handling this.

thanks, sirish.

the simple solution is: don't create 100000 threads, use executorservice (eg use 1 of ready use executors).

that way can control maximum number of parallel jobs executed.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -