关于JSP 实例方法的线程安全
我测试了下面的代码段,可还是得不出个结论来,还请各位大虾指点迷津。
代码如下:
--------
<%--
Copyright (c) 2002 by Phil Hanna
All rights reserved.
You may study, use, modify, and distribute this
software for any purpose provided that this
copyright notice appears in all copies.
This software is provided without warranty
either expressed or implied.
--%>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%!
// int c;
// static public int sum(int a, int b)
public int sum(int a, int b)
{
int c = 0;
try{
Thread.sleep(350);
}
catch(Exception e)
{
e.printStackTrace();
}
c = a + b;
try{
Thread.sleep(750);
}
catch(Exception e)
{
e.printStackTrace();
}
return c;
}
%>
<%
String requestTime =
new SimpleDateFormat("hh:mm:ss ").format(new Date());
for (int i = 0; i < 22; i++) {
%>
Request at <%= requestTime %> 2 + 2 = <%= sum(2,2) %><br>
<%
// Thread.sleep(750);
}
%>
请问在sum()方法中的变量c,是否存在线程安全问题? 如果c是定义在
JSP Declaration 部分的类的对象时,是否也存在线程安全问题?
如能指教,本人不胜感激。