Hi ,

This morning I did a simple testing about
[cocurrent programming] + [Servlet]  :-)

0
      a
            *  I use J2SE1.3 + Jsdk2.1 as Servlet engine
            *  I use J2SE1.3  to start two Java Applications
      b    I use 3 "DOS Command Prompt" :
               *  one for Servlet engine
               *  one for the first Java Application which use URLConnection
                   to communicate to my Servlet.
               *  one for the second Java Application which use URLConnection
                   to communicate to my Servlet.


1
      a   the the following is my Servlet code:
*************************************************
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.net.*;
import java.util.*;

public class servlet_ht extends HttpServlet {
ObjectOutputStream os=null;
ObjectInputStream is=null;
String s_tmp=null;

Object sync=new Object();


public void init(ServletConfig config) throws ServletException {
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
int i=0;
synchronized(sync){

System.out.println("get a GET...");
try{
response.setContentType("application/octet-stream");
os=new ObjectOutputStream( response.getOutputStream() );
os.writeObject("in GET=aaaaa");
os.flush();

os.close(); os=null;

   while(i<10){
   System.out.println("P1="+request.getParameter("P1")+"
thread="+Thread.currentThread() );
   i++;
   Thread.currentThread().sleep(1000);
   }
}catch(Exception e){System.out.println("e="+e);}

sync.notifyAll();
}

}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
System.out.println("get a POST...");
...
}


public String getServletInfo(){
return "servlet_ht";
}

}//class
*************************************************


      b   the the following is my Java Application code:
*************************************************
import java.applet.Applet;

import java.net.*;
import java.io.*;


public class applet_ht extends Applet  {

String input=null;

public void init() {
URL url=null;
//HttpURLConnection con=null;
URLConnection con=null;
ObjectOutputStream os=null;
ObjectInputStream is=null;
String s_tmp=null;

try{
url=new URL("http://xxx.xxx.xxx.xxx:8080/servlet/servlet_ht?P1="+input);
con=(URLConnection)url.openConnection();
//con=(HttpURLConnection)url.openConnection();
//con.setRequestMethod("GET");
con.setUseCaches(false);
con.setRequestProperty("CONTENT_TYPE", "application/octet-stream");
con.setDoInput(true);
con.setDoOutput(true);

is=new ObjectInputStream(con.getInputStream());
s_tmp=(String)is.readObject();
System.out.println("in send, return from servlet ="+s_tmp);
//s_tmp=null;

is.close(); is=null;
//os.close(); os=null;

}catch(Exception e){System.out.println("e="+e);}

}

public static void main(String[] args) {
applet_ht xxx=new applet_ht();
xxx.input=args[0];
xxx.init();
}

}
*************************************************


2   The following is the "steps" of this testing:
      [a]   I run "java applet_ht 11111" to start the
             first Java Application JUST after I
             run [b]
      [b]   I run "java applet_ht 22222" to start the
             second Java Application JUST after I
             run [a]
      [c]   I continue to do [a] and [b] :-) :-) :-) [ This
             is a little bit like playing drum :-) ]

3
2   The following is the result of this testing:
     Before my arms and fingers are sour, :-) :-) :-) I have
     done many times of such testing:
       a  in the "Command Prompt" of Servlet engine,
          I always get 10 "11111" or 10 "22222",  I never
          find the "cross :-)" of several "11111" and "22222".
       b and every time the thread name  is different, for
          example,
           ...
          Thread[Thread-10,5,main]
          Thread[Thread-11,5,main]
          Thread[Thread-12,5,main]
          ...


Can this testing prove that we can lock some codes
in Servlet ? :-)   I hope so,  otherwise my arms are
sour for nothing :-) :-) :-)


 1.99999 cent provider -- Bo ArmStrong  :-) :-)


Oct. 06, 2000

___________________________________________________________________________
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

Reply via email to