----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files. Don't make us guess your problem!!!
----------------------------------------------------------------
The following servlet code will output on my browser something like:
1.891:ligne 1
1.891:ligne 2
1.891:ligne 3
1.891:ligne 4
1.891:ligne 5
1.891:this is the end
The first number is an instance variable and second one a class variable
(static).
If I started to browser at the same time I have something like:
Browser 1:
4.892:ligne 1
5.893:ligne 2
5.893:ligne 3
5.893:ligne 4
5.893:ligne 5
5.893:this is the end
Browser 2:
5.893:ligne 1
5.893:ligne 2
5.893:ligne 3
5.893:ligne 4
5.893:ligne 5
5.893:this is the end
The class variable (second number) is increment in the first browser as soon as
the second one do it.
The weird thing is that the instance variable do the same thing.
I would prefer :
Browser 1:
4.892:ligne 1
4.893:ligne 2
4.893:ligne 3
4.893:ligne 4
4.893:ligne 5
4.893:this is the end
Browser 2:
5.893:ligne 1
5.893:ligne 2
5.893:ligne 3
5.893:ligne 4
5.893:ligne 5
5.893:this is the end
Is this a bug, a feature or I missed something?
I'm using Linux/Apache 1.3.11/Jdk 1.2/Jserv 1.1
thanks
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import sun.misc.*;
import java.util.*;
public class Svtest extends HttpServlet {
int id=0;
volatile static int globalid=888;
public void doGet ( HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
synchronized (this) {
id++;
globalid++;
}
PrintWriter out=null;
try {
logger=new PrintWriter(new
FileOutputStream("/import/tmp/svtest.log",true),true);
} catch (Exception e) {
}
response.setContentType ("text/html");
out = response.getWriter();
try {
printit("ligne 1",out);
Thread.sleep(5000);
printit("ligne 2",out);
Thread.sleep(5000);
printit("ligne 3",out);
Thread.sleep(5000);
printit("ligne 4",out);
Thread.sleep(5000);
printit("ligne 5",out);
} catch (Exception e) {
}
printit("this is the end",out);
out.close();
response.getOutputStream().close();
}
public synchronized void printit(String msg, PrintWriter out) {
out.println(id + "." + globalid + ":" + msg + "<br>");
out.flush();
}
}
--
Jean-Sebastien Bettez
8D Technologies inc.
http://www.8D.com
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]