Hi Stan,
I'm posting some of the code. The results.jsp instantiates the SearchClient class and calls the search() method which returns an arraylist. The search method spawns two new threads which communicate with two local servers. The communication protocol between the thread and the local servers is a message (server) - ack(client) protocol.
The threads are getting created and the communication with servers is also established. The local servers return one object at a time from which the thread builds an array, merges the two arrays from the two servers into an array list and returns it. For every object from server, the thread has to send an ack.
My problem is the thread is not sending the ack to the server. So the servers block after sending the first object, meanwhile the jsp code doesnt wait and continue with it execution.
Here is the code...pls dont mind the indentation
/** results.jsp */
<%@ page import = "javax.servlet.*, javax.servlet.http.*, java.io.*,java.util.ArrayList, com.URLMap, com.SDoc, com.SearchClient "%>
<%@ page isThreadSafe="true"%>
<%@include file="index.jsp"%>
<%
if(URLMap.size()==0){
URLMap.buildMap();
}
String query=request.getParameter("query");
String context = request.getParameter("context");
String lastScore = "0";
if(lastScore==null)
lastScore="0";
SearchClient sc = new SearchClient(query,context,lastScore);
ArrayList<SDoc> results = new ArrayList<SDoc>();
results = sc.search();
%>
/** results.jsp */
/** SearchClient.search() */
public ArrayList<SDoc> search(){
ArrayList<SDoc> results = new ArrayList<SDoc>();
try{
SearchThread st1 = new SearchThread(localServers[0],qry,ct);
SearchThread st2 = new SearchThread(localServers[1],qry,ct);
st1.run();
st2.run();
System.out.println("local server threads started");
//st2.join();
//st1.join();
//System.out.println("results are " + doc128.get(1).getScore() + doc87.size());
int i=0,j=0,k=0;
........ more code here
/** SearchClient.search() */
/** SearchThread.run */
public synchronized void run(){
//System.out.println("inside SearchThread.run");
try{
//sleep(100);
int newControlPort=0;
int newDataPort=0;
inLine="nothing";
outLine="";
client = new Socket(ip,4444);
out= new PrintWriter(client.getOutputStream(),true);
in= new BufferedReader(new InputStreamReader(client.getInputStream()));
System.out.println("initialized in and out on" + client.getPort() + client.getLocalSocketAddress());
while(!in.ready()){
//System.out.println("waiting for server ready");
yield();
}
new ControlPort=Integer.parseInt(in.readLine().trim());
if(newControlPort!=0){
System.out.println("new control port is " + newControlPort);
out.close();
in.close();
client.close();
try{
controlClient = new Socket(ip,newControlPort);
System.out.println("new control port is " + controlClient.getPort());
}catch(IOException ie){
ie.printStackTrace();
}
/** SearchThread.run */