对于servlet,javaBean内部的static数据,是否需要考虑同步访问呢?

jjc822 2007-11-14 10:18:41
请问各位在职的J2EE web开发的,对于servlet,javaBean内部的static数据,是否需要考虑同步访问呢?

我曾经在群上讨论过,但是在servlet的生命周期上遇到了问题,所以至今还未能明确!

希望能够得到企业版的回复!一般教材是没有考虑也没有提及这个问题!
...全文
150 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Graywolf8888 2007-11-20
  • 打赏
  • 举报
回复
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;

public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {

private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

private static java.util.List _jspx_dependants;

private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.AnnotationProcessor _jsp_annotationprocessor;

public Object getDependants() {
return _jspx_dependants;
}

public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
}

public void _jspDestroy() {
}

public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {

PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;


try {
response.setContentType("text/html;charset=UTF-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;

out.write('\r');
out.write('\n');

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

out.write("\r\n");
out.write("\r\n");
out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n");
out.write("<HTML>\r\n");
out.write("<head>\r\n");
out.write("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=gb2312\">\r\n");
out.write("<link rel=\"Shortcut Icon\" href=\"favicon.ico\"> \r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("<h1>HI,I AM HERE!</h1>\r\n");
out.write("</body>\r\n");
out.write("<!--BODY ID=TestActivexInHTMLDlg BGCOLOR=LIGHTGREY ActName=''>\r\n");
out.write("<TABLE WIDTH=100% HEIGHT=100%>\r\n");
out.write("<TR WIDTH=100% HEIGHT=80%>\r\n");
out.write("<TD ALIGN=CENTER VALIGN=BOTTOM>\r\n");
out.write("\r\n");
out.write("<!--以下参数功能,请参考相关文档-->\r\n");
out.write("\r\n");
out.write("<!--Object id=\"BoBo\" width=600 height=460 classid='clsid:EC0978ED-24E3-403C-AB7A-060E388553E6' codebase='http://www.17bobo.com/Software/BoBo_ActiveX_V3.ocx'>\r\n");
out.write("<PARAM NAME=\"MaxLinkCount\" VALUE=100>\r\n");
out.write("<PARAM NAME=\"MaxCacheTimeS\" VALUE=120>\r\n");
out.write("<PARAM NAME=\"MinCacheTimeS\" VALUE=60>\r\n");
out.write("<PARAM NAME=\"MaxCacheSizeMB\" VALUE=150>\r\n");
out.write("<PARAM NAME=\"MaxDownloadKbps\" VALUE=0>\r\n");
out.write("<PARAM NAME=\"MaxUploadKbps\" VALUE=0>\r\n");
out.write("<PARAM NAME=\"RealMediaType\" VALUE=\".mp4,.mp3\">\r\n");
out.write("<PARAM NAME=\"TextAd\" VALUE=\"BoBo\">\r\n");
out.write("<PARAM NAME=\"PlayFlvFile\" VALUE=\"http://www.boloso.com/bobo/boboflv.swf\">\r\n");
out.write("<PARAM NAME=\"BCServerURL\" VALUE=\"http://www.17bobo.com\">\r\n");
out.write("<PARAM NAME=\"ActName\" VALUE=\"rm/2.rm?Sd2b350c1_9ba87_24051e__f47_57\">\r\n");
out.write("</Object><br>\r\n");
out.write("</TD>\r\n");
out.write("</TR>\r\n");
out.write("<TD>\r\n");
out.write("</TABLE>\r\n");
out.write("</BODY-->\r\n");
out.write("</HTML>");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try { out.clearBuffer(); } catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}

有兴趣可以研究下,学东西就要学精,其它就触类旁通,我正在努力
LZ加油
Graywolf8888 2007-11-20
  • 打赏
  • 举报
回复
LZ,JavaBean是相当于用在Servlet方法里的变量。。。。
看来你还没有完全搞清楚什么是JSP,Servlet。
JSP在TOMCAT之类的服务器里被转化成为Servlet,所有写在JSP里的东西,多数被转化Servlet方法里的东西
你不信去看看TOMCAT里工作的目录,里边是对于每个JSP都有一个SERVLET。。。
把我的目录,给你参考下。。。
C:\Program Files\Apache Software Foundation\Tomcat 6.0\work\Catalina\localhost\springapp\org\apache\jsp\WEB_002dINF\jsp\product_jsp.java

内容如下:
package org.apache.jsp.WEB_002dINF.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class product_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {

}

内容太长,帖不下来。。。。。
jjc822 2007-11-16
  • 打赏
  • 举报
回复
前面多数是讨论servlet的,可以讨论javaBean的吗?^_^
honbo 2007-11-15
  • 打赏
  • 举报
回复
看实现的方法了,需要同步的就必须同步阿
coolzyt 2007-11-14
  • 打赏
  • 举报
回复
servlet最佳实践:不要定义类变量或实例变量,一切都写在方法体内,就可以避免同步问题。
jjc822 2007-11-14
  • 打赏
  • 举报
回复
对于经常改变值的static数据,应该要考虑同步读取的吧!

还有对于servlet,javaBean内部数据,除了static数据外,其他的数据也需要考虑吗?!
Graywolf8888 2007-11-14
  • 打赏
  • 举报
回复
当然要考虑同步了,Servlet本身是基于多线程的。。。
wyhlgx 2007-11-14
  • 打赏
  • 举报
回复
不清楚问题说的什么,一般静态数据是不需要同步的。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧