Setting up simultaneous queries shouldn't be a problem and shouldn't require
synchronization. I have done something similar where I used JavaScript to
send the query outputs to different windows/frames.
To keep the two queries from stomping on each other, create your data access
methods in a separate data class. That way each request get's it's own data
class instance to execute the query. In the snippet below, each one of
queries sends the servlet a different queryType ("query1" or "query2").
<snippet>
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
hSessionObjects = new Hashtable();
// bundle-up session objects
hSessionObjects.put("MyServlet.request", req);
hSessionObjects.put("MyServlet.response", res);
hSessionObjects.put("MyServlet.out", out);
MyData md = new MyData(hSessionObjects);
String queryType = req.getParameter("queryType");
// based on type of query... execute a different method
if (queryType.equals("query1")){
md.doQuery1();
}else{
md.doQuery2();
}
}
public class Mydata {
private PrintWriter out;
private HttpServletResponse res;
private HttpServletRequest req;
private Hashtable hDataObjects;
MyData(Hashtable hash){
hDataObjects = new Hashtable();
hDataObjects = hash;
this.res =
(HttpServletResponse)hDataObjects.get("MyServlet.response");
this.out = (PrintWriter)hDataObjects.get("MyServlet.out");
this.req = (HttpServletRequest)hDataObjects.get("MyServlet.request");
}
public void doQuery1(){
String queryString = req.getParameter("queryString");
// execute the query
// print the results
out.println(.....);
}
public void doQuery2(){
String queryString = req.getParameter("queryString");
// execute the query
// print the results
out.println(.....);
}
}
<end snippet>
I would take this approach one step further by replacing the MyData() with
MyHtml() (HTML class for the presentation). The HTML class would then have
methods to call the MyData() methods. Now you separate the data and
presentation layers (MVC). The servlet acts as the Controller.
Hope this helps
John Kirby
DISC
> > > Specific problem:
> > > My servlets serve as an ecommerce-system:
> > > 1. To navigate through the resultset of a database-query I set a
cookie
> > > (identifies set of products) to the client
> > > 2. The user post two simultanious querys -> the slower query-process
> > > sets the final cookie.
> > > 3. So the user navigate in both browser windows throw the same set of
> > > products!
> > >
> > > thanks martin
> > >
> > >
___________________________________________________________________________
> > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> > > of the message "signoff SERVLET-INTEREST".
> > >
> > > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > > Resources:
http://java.sun.com/products/servlet/external-resources.html
> > > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
Cezar Totth email: [EMAIL PROTECTED]
Fax: (401) 220 33 95
Genesys Software Romania Phone: (401) 638 49 44
Stefan Furtuna 169, sect.6
cod 77171, Bucharest
Romania
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html