今天公司网站测试,访问量一上来tomcat就报错说堆已经满了,一从起没过5秒钟又死了,一直就是这样,所以问大家一些问题1、我一个页面假如就new 3个对象,这些对象会放在jvm的堆里是吧,对象引用会放在栈里,如果一分钟内有500个人访问我服务器中的一个页面,那堆里至少就有1500个对象,这样会不会web服务器承受不了压力,因为jvm也没来得及垃圾回收,像这种情况大家都怎么办啊~~~
我还想问一下大家如何优化tomcat的,包括程序中如何优化,包括bean的创建优化~~
我还想问一下大家如何优化tomcat的,包括程序中如何优化,包括bean的创建优化~~
关注学习对于那个new 对象
我觉得 你如果没有使用spring 就应该
靠工厂 控制对象的创建个数
该单例 单例 该多例的多例下面的是我曾经写的一个打印圣诞树的东西
你可以看到 其实 仅仅能创建3 个对象public abstract class Style {
/** 圣诞树的层数*/
public int level = 10; public static String STYLE_1 = "style1"; public static String STYLE_2 = "style2"; public static String STYLE_3 = "style3"; public static Hashtable<String, Style> value = new Hashtable<String, Style>();
/**
* 业务方法 打印*
*/
public abstract void doPrint();
/**
* 工厂
* @param style
* @return
*/
public static Style getStyle(String style) {
if (style.equals(STYLE_1)) {
if (value.get(Style.STYLE_1) != null)
return (Style) value.get(Style.STYLE_1);
else {
Style style1 = new Style1();
value.put(Style.STYLE_1, style1);
return style1;
}
}
if (style.equals(STYLE_2)) {
if (value.get(Style.STYLE_2) != null)
return (Style) value.get(Style.STYLE_2);
else {
Style style2 = new Style2();
value.put(Style.STYLE_2, style2);
return style2;
}
}
if (style.equals(STYLE_3)) {
if (value.get(Style.STYLE_3) != null)
return (Style) value.get(Style.STYLE_3);
else {
Style style3 = new Style3();
value.put(Style.STYLE_3, style3);
return style3;
}
} else
return null;
} public int getLevel() {
return level;
} public void setLevel(int level) {
this.level = level;
};
}
如收到请求transcount++,
处理完一个transcount--,当然这是application级别的