Mohit H
Mohit H

Reputation: 959

Java concurrency handling

For concurrency handling i have written and executor class :

ExecutorService service = Executors.newFixedThreadPool(10);
                    Future<List<Content>> submit = service.submit(new PushClass(pushlist, content));
                    List<Content> resu = submit.get();

and Below is the push class that implements the Callable interface :

 public class PushClass implements Callable<List<Content>> {

List<Content> ls;
String content;

public PushClass(List<Content> ls, String content) {
    this.ls = ls;
    this.content = content;
}

private synchronized String push(String msisdn, String content, String Cli) {

       // hitting the push url
    } catch (Exception e) {
        e.printStackTrace();
    }

    return status;

}

@Override
public List<Content> call() throws Exception {

    for (Content c : ls) {
        c.setResponse(push(c.getMsisdn(), content, c.getCli()));
    }
    return ls;
}

Upto what limit can i increase the thread to as to prevent any queuing in the server or can i make the pool dynamic ? Sometimes tomcat is showing error as , "The Other thread are in process" , can i dynamically scale it.

Upvotes: 2

Views: 132

Answers (1)

user1933888
user1933888

Reputation: 3017

  1. Yes connection pooling will help manage db resources better, just open connection once and return it back to pool, instead of closing, about the pool size I leave it upto you (Even one may suffice)
  2. The best thing you can do to improve performance is batchUpdate i.e. commit the transaction to db only after some 500-1000 records to get rid of the db overhead
  3. You can bring in multiple threads to take the incoming load, multi-threading should be simple in your case since the operation to be done is atomic in nature (assuming you only have inserts), please explore java ExecutorService for this. ThreadPoolExecutor, you can select no. of threads based on testing, start with 10.

Upvotes: 3

Related Questions