由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Tomcat Servlet: synchronized vs non-synchronized methods
相关主题
求助!Tomcat下设置servlets的问题servlet的精华到底是啥?
大家都是怎么自学J2EE的servlet是否可以在doGet里面返回304
HashMap cacheQuestion about Model 2
运行servlet时出现的http status 404问题Run Servlet with Tomcat
一个servlet问题One more servlet Q: Http Session
A Servlet query string questionHelp on compiling servlet with Tomcat
不明白servlet, applet到底啥区别,还有jspPlease Help!
Servlet如何Stream mp3文件?How to make php and servlet work togethe
相关话题的讨论汇总
话题: servlet话题: cpu话题: tomcat话题: different
进入Java版参与讨论
1 (共1页)
l*****b
发帖数: 82
1
am testing the servlet application using tomcat and customized multithreded
test clients. I try the following different scenarios - synchronize or not
the servlet method. In client side, I generate 200 concurrent requests to
this servlet. There are quite different CPU usage in this scenarios: non-
synchronized one use much more CPU (almost 100%) than synchronized (as usual
). Could anyone advise me what's happened there and why has that different?
e.g.
public TestServlet .....{
public void doGet
m******t
发帖数: 2416
2

multithreded
usual
Execution in handleRequest() is serialized with
the synchronized version, hence the low cpu utilization.

【在 l*****b 的大作中提到】
: am testing the servlet application using tomcat and customized multithreded
: test clients. I try the following different scenarios - synchronize or not
: the servlet method. In client side, I generate 200 concurrent requests to
: this servlet. There are quite different CPU usage in this scenarios: non-
: synchronized one use much more CPU (almost 100%) than synchronized (as usual
: ). Could anyone advise me what's happened there and why has that different?
: e.g.
: public TestServlet .....{
: public void doGet

l*****b
发帖数: 82
3
Hi, magicfat , thank you. Many suggest to take "synchronized" out. My
Servlet has no any instance or static variable. Could I assume the un-
synchronized method is still thread safe? And this high CPU usage is normal
case for un-synchronized method?
F****n
发帖数: 3271
4
Why you so care about high CPU usage? It means your requests are handled
concurrently and therefore faster. Servlet should not have state in most
cases, so there is really no need to make it thread safe. If you need to
access some stateful data, put them into some objects and make them thread
safe.

normal

【在 l*****b 的大作中提到】
: Hi, magicfat , thank you. Many suggest to take "synchronized" out. My
: Servlet has no any instance or static variable. Could I assume the un-
: synchronized method is still thread safe? And this high CPU usage is normal
: case for un-synchronized method?

l*****b
发帖数: 82
5
Hi, all, many thanks. Your advice is helpful indeed. BTW, I am a performance
zealot.
F****n
发帖数: 3271
6
But high CPU usage actually means it's faster (No waiting line!)

performance

【在 l*****b 的大作中提到】
: Hi, all, many thanks. Your advice is helpful indeed. BTW, I am a performance
: zealot.

m******t
发帖数: 2416
7

performance
Well, as Foxman said, high CPU utilization is
A Good Thing(tm). 8-)
(Not too high though, you want to keep the running
average under 50% or even lower)

【在 l*****b 的大作中提到】
: Hi, all, many thanks. Your advice is helpful indeed. BTW, I am a performance
: zealot.

1 (共1页)
进入Java版参与讨论
相关主题
How to make php and servlet work togethe一个servlet问题
大家做JSP/Java开发的配置是怎样的?A Servlet query string question
[转载] 急!在线等---从Servlet调用AXIS的Web Service 遇到问题!不明白servlet, applet到底啥区别,还有jsp
Re: [转载] 急!在线等---从Servlet调用AXIS的Web ServServlet如何Stream mp3文件?
求助!Tomcat下设置servlets的问题servlet的精华到底是啥?
大家都是怎么自学J2EE的servlet是否可以在doGet里面返回304
HashMap cacheQuestion about Model 2
运行servlet时出现的http status 404问题Run Servlet with Tomcat
相关话题的讨论汇总
话题: servlet话题: cpu话题: tomcat话题: different