In my Java application I want to have a pool of threads (I use ExecutorService for this) that connect to a memcached server to issue some requests. I would like that each Thread has its own connection that is opened once and should be kept during the whole running time. I was planning to use the following code that I found in another question:
Executor Service
ExecutorService threadPool =
Executors.newFixedThreadPool(5, Executors.defaultThreadFactory());
Runnables executed by the Threads in the pool
public class SocketTask implements Runnable {
private String workDetails;
private static final ThreadLocal threadLocal =
new ThreadLocal(){
@Override
protected Socket initialValue(){
return new Socket();
}
};
public SocketTask(String details){
this.workDetails = details;
}
public void run(){
Socket s = getSocket(); //gets from threadlocal
//send data on socket based on workDetails, etc.
}
public static Socket getSocket(){
return threadLocal.get();
}
}
My question is, when I initialize the socket how can I do it so I am able to pass an argument (say a String with the IP of the memcached server) to the new Socket() call?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)