- 浏览: 284158 次
- 性别:
- 来自: 兰州
文章分类
- 全部博客 (116)
- 给网友答疑 (1)
- J2EE (16)
- DesignPattern (14)
- OtherArchive (5)
- lucene and compass (1)
- JasperReport (2)
- FusionCharts (2)
- Classical algorithm (2)
- JS (5)
- ZK Ajax (1)
- ubuntu-linux (4)
- Weka (0)
- IDE Config (6)
- JAVA 底层 (3)
- C\C++ (4)
- Android (15)
- 项目展示 (1)
- 娱乐生活 (16)
- 电驴资源 (1)
- 网络转载 (1)
- 程序员 毛病 (1)
- Android,开发日志 (2)
- java (1)
- openGL es (2)
- MAC (1)
最新评论
-
洋葱pp奥特曼:
求大神再发一次资源,万分感激!!小弟邮箱:173992660@ ...
使用JQuery-Week-Calendar做日程 -
xbliu564:
请问版本号
fusionchart 破解文件SWF -
xue_lang:
看了半天,有点坑爹的赶脚,哎
状态模式(State) -
teacup_madman:
我只能说。这个程序可以去掉的地方太多了。这个真的是State模 ...
状态模式(State) -
冬日的阳光:
TrafficLight这个类的change方法可以改一下,如 ...
状态模式(State)
写点程序就要认真点,为什么呢?会有效率问题的!引例:
今天电力公司的满意度测评系统开始正式的运行测评了,然而有一件很溴的事情让人难看,前面填写一份问卷不到10秒钟的时间,现在呢?有多少时间呢?2分钟,两天以后5分钟,三天以后10分钟,...N天以后40分钟,还伴随着有什么情况呢?
tomcat6.0 cup 100% 内存:512
这真是让人想都不敢想的事情,居然发生呢?居然做了一下的假设:
1。本来以为是Tomcat运行时间很长了,不稳定的原因;
2。本系统装载小型机的虚拟机上,并且虚拟机有异常,怀疑是不是系统的问题;
3。使用的连接池+mysql,是不是mysql连接数堵塞的原因。
。。。。。。。。。。
种种的假设都有了,就是没有检查源代码。
很致命的源代码见如下:
public String add() { String result = "tip"; if (StringUtils.isEmpty(indexItemids)) { setOperationMessage("你交了一张白卷,请重新填写问卷!<br><a href='/paper/paperItem!queryAll.action'>重新填写</a>"); return "tip"; } survey = surveyManager.querySurvey(survey.getSurveyID()); customerType = customerTypeManager.queryCustomerType(customerType.getCustomerTypeID()); surveyArea = surveyAreaManager.querySurveyArea(surveyArea.getSurveyAreaID()); String[] itemids = indexItemids.split(":"); String[] scores = itemScores.split(":"); user = randomGenerateMethod(); UserInfo uInfo = user.getUserInfo(); // 添加调查结果 SurveyResult surveyResult = surveyResultSaveOrUpdate(user); // 添加调查结果项 surveyResultItemSaveOrUpdate(surveyResult, itemids, scores); // 添加调查结果致地区客户类别调查结果 customerTypeResultSaveOrUpdate(surveyResult, itemids, scores, uInfo); // 添加建议项 List<Suggest> haveSuggests = new ArrayList<Suggest>(); if (null != suggestids) { for (int id : suggestids) { Suggest suggest = suggestManager.querySuggest(id); haveSuggests.add(suggest); } } user.getUserInfo().setSuggests(haveSuggests); user.setAccountlocked(true); user.getUserInfo().setCustomerName(userInfo.getCustomerName()); user.getUserInfo().setCustomerUnit(userInfo.getCustomerUnit()); user.getUserInfo().setAddress(userInfo.getAddress()); user.getUserInfo().setPhone(userInfo.getPhone()); user.getUserInfo().setCustomerAdvice(userInfo.getCustomerAdvice()); user.getUserInfo().setTradeClass(userInfo.getTradeClass()); user.getUserInfo().setAge(userInfo.getAge()); user.getUserInfo().setSex(userInfo.getSex()); user.getUserInfo().setOccupationClass(userInfo.getOccupationClass()); userManager.modifyUser(user); setOperationMessage("您的问卷信息已经成功提交,感谢您的参与,再见!"); return result; } private SurveyResult surveyResultSaveOrUpdate(User user) { SurveyResult surveyResult = surveyResultManager.querySurveyResult(user.getUserInfo().getSurvey(), user); if (surveyResult == null) { surveyResult = new SurveyResult(); surveyResult.setSurvey(user.getUserInfo().getSurvey()); surveyResult.setTime(new Date()); surveyResult.setUser(user); surveyResultManager.addSurveyResult(surveyResult); } else { surveyResult.setSurvey(user.getUserInfo().getSurvey()); surveyResult.setTime(new Date()); surveyResult.setUser(user); surveyResultManager.modifySurveyResult(surveyResult); } return surveyResult; } private void surveyResultItemSaveOrUpdate(SurveyResult surveyResult, String[] itemids, String[] scores) { for (int i = 0; i < itemids.length; i++) { SurveyResultItem surveyResultItem = null; int indexItemID = Integer.parseInt(itemids[i]); double itemScore = Double.parseDouble(scores[i]); indexItem = indexItemManager.queryIndexItem(indexItemID); if (null == surveyResultItemManager.querySurveyResultItem(indexItem, surveyResult)) { surveyResultItem = new SurveyResultItem(); surveyResultItem.setIndexItem(indexItem); surveyResultItem.setSurveyResult(surveyResult); surveyResultItem.setItemScore(itemScore); surveyResultItemManager.addSurveyResultItem(surveyResultItem); } else { surveyResultItem = surveyResultItemManager.querySurveyResultItem(indexItem, surveyResult); surveyResultItem.setIndexItem(indexItem); surveyResultItem.setSurveyResult(surveyResult); surveyResultItem.setItemScore(itemScore); surveyResultItemManager.modifySurveyResultItem(surveyResultItem); } } } private void customerTypeResultSaveOrUpdate(SurveyResult surveyResult, String[] itemids, String[] scores, UserInfo uInfo) { for (int i = 0; i < itemids.length; i++) { int indexItemID = Integer.parseInt(itemids[i]); indexItem = indexItemManager.queryIndexItem(indexItemID); double itemScore = Double.parseDouble(scores[i]); customerTypeResult = customerTypeResultDao.getCustomerTypeResultByIndexItemAndCustomerType(indexItem, uInfo.getSurveyArea(), uInfo.getSurvey(), uInfo.getCustomerType()); if (customerTypeResult == null) { customerTypeResult = new CustomerTypeResult(); customerTypeResult.setIndexItem(indexItem); customerTypeResult.setItemScore(itemScore); customerTypeResult.setSurvey(uInfo.getSurvey()); customerTypeResult.setSurveyArea(uInfo.getSurveyArea()); customerTypeResult.setCustomerType(uInfo.getCustomerType()); customerTypeResultDao.addCustomerTypeResult(customerTypeResult); } else { customerTypeResult.setIndexItem(indexItem); customerTypeResult.setItemScore(itemScore); customerTypeResult.setSurvey(uInfo.getSurvey()); customerTypeResult.setSurveyArea(uInfo.getSurveyArea()); customerTypeResult.setCustomerType(uInfo.getCustomerType()); customerTypeResultDao.modifyCustomerTypeResult(customerTypeResult); } } }
看见这点代码本来角色没有什么,因为都是固定的,怎么会有这样大的效率差别呢? 再来看看一下的代码:
@Override public SurveyResult querySurveyResult(Survey survey, User user) { SurveyResult result = null; for (SurveyResult surveyResult : queryAllSurveyResult().getResultlist()) { if (user.getUserID() == surveyResult.getUser().getUserID()) { if (survey.getSurveyID() == surveyResult.getSurvey().getSurveyID()) { result = surveyResultDao.querySurveyResult(surveyResult.getSurveyResultID()); } } } return result; }
这个代码会不会哟效率的问题呢? 再来看看一下的代码:
@Override public SurveyResult querySurveyResult(Survey survey, User user) { SurveyResult result = null; StringBuffer wherejpql = new StringBuffer(" o.survey.surveyID=?1 and o.user.userID=?2 "); Integer[] params = new Integer[] { survey.getSurveyID(), user.getUserID() }; List<SurveyResult> temps = surveyResultDao.queryAllSurveyResult(-1, -1, wherejpql.toString(), params, null).getResultlist(); if (temps != null && temps.size() == 1) { result = temps.get(0); } return result; }
上面的代码的实行时间在1356条的时候是0:01:30,而这些代码的执行时间呢?0.002S效率在那呢?因为伴随业务逻辑循环在变大。
总结:
1。其实写循环没有什么,只是不要随业务逻辑的增加而循环量增大就可以了!
2。循环很好CUP,尤其是大循环。
发表评论
-
Spring MVC 和 Struts2 比较
2011-02-28 16:55 19861.struts2框架是类级别的拦截,每次来了请求就创建一个A ... -
写点程序的那些糗事(2)
2010-12-16 14:29 1092昨天给商学院做的专家品审系统正式的运行了,来的全部是一些大领导 ... -
Spring3 mvc 国际化时的一点注意
2010-12-13 09:37 1701Spring3 MVC 中:如果使用国际化的形式,如 ... -
MySQLIntegrityConstraintViolationException 解决办法
2010-10-19 16:51 18778使用JPA做映射: /** * 指标 * ... -
编程语言结构图
2010-09-23 12:22 1158编程语言就是这么个样子的!还要讨论什么是“排名战”么? ... -
在线试听(播放器)防止盗链下载实现讨论_障眼法实现
2010-09-06 12:10 6241《读者》电子出版平台有个附属项目,需求描述是这样的: ... -
JavaMail、Commons Email发送邮件 出现结果后到的文件是Base64的问题的解决办法
2010-08-19 23:09 5191今天折腾了一天,有个业务需要写个简单的邮件发送,但是测试了。从 ... -
使用jcaptcha 仿论坛tip 生成异步验证码
2010-08-18 03:55 2075首先看看效果图: 如上图,点击验证码可以异步的刷新 ... -
Eclipse 3.6 插件资源-持续更新ing-更新15次--欢迎有好用插件的朋友推荐
2010-08-17 11:00 7657欢迎有好用插件的朋友推荐! 注:没有提示说明安装的,直 ... -
Jpa 时间段间的查询问题解决办法
2010-05-27 22:13 22583最近在做法院的一个档案管理项目,一直做的的查询是基于compa ... -
dhtmlXTree 与后台交互数据
2009-11-06 14:44 1859今天要写一个获得dhtmlXTree 节点值的,大量的Id节点 ... -
Struts2 OGNL中的投影(过滤)与软件工程
2009-11-05 11:54 1859Struts2 OGNL中的投影(过滤) <s: ... -
Struts2 doubleSelect
2009-10-30 14:17 1486今天要用到一个二级联动,以前都是使用JavaScript编写, ... -
Struts2 的三种接受参数的方式
2009-10-28 16:59 19981、通过普通参数的getter and setter方式 ... -
JDBC CRUD操作的粗略封装DEMO
2009-10-15 12:19 4567暮然回首,看看jDBC的操作,原来很多的东西都忘记了, ...
相关推荐
仿糗事百科微信小程序 1. 实现顶部页签菜单左右滑动效果 2. 实现顶部页签菜单切换效果,页签菜单选中时字体加粗,同时对应的内容也跟着变化 3. 实现专享界面糗事列表设计,包括发布人头像、发布人昵称、发布的段子等...
高仿糗事百科程序源码 免费
uni-app实战仿糗事百科开发前端源码带素材 资源目录: 【20190705更新】【前端完整代码】仿糗事百科.rar 【前端完整代码】【更新至256课时】仿糗事百科.rar App截图.rar socket测试工具.rar 图标.rar 图片素材.rar
python程序用于自动获取糗事百科的内容
莫仿糗事百科
2013最新糗事百科源码|捧腹网源码|笑话类源码,yicms商业版内核,2套模板,含会员中心,完全开源,请放心使用。也是转来的,没有测试,自行测试,不喜欢的不要下,不存在骗分的说法。解压密码见注释
微信小程序案例:仿糗事百科源码
糗事百科 系统的源码 可以拿来学习 希望对大家有帮助
最新2014仿糗事百科主题,PHP开发仿糗事百科主题!
2013最新仿糗事百科源码 欢迎下载,已测试完整
亲测有效,不管是windows 还是Linux都...使用python 爬取糗事百科的段子,通过回车键控制,一次一个,同时可以把看过的内容保存到本地查看 具体实现可以参照 http://blog.csdn.net/qiqiyingse/article/details/60583129
该程序为仿新版的糗事百科客户端,数据是通过jsoup来抓取糗事百科网页版的,程序能正常运行,由于原客户端中有些功能模块的数据不能通过网页中抓取到,所有这类功能模块没有实现。程序sdk为android 4.0以上的版本,...
获取糗事百科段子程序,拥有UI交互界面 下载之后无需任何配置,可以直接运行 具体的程序请参考:http://blog.csdn.net/qiqiyingse/article/details/64522690
糗事百科的源码,有需要的可以看看,只要5积分就可以下载了
糗事百科windows桌面客户端-纯文字版 程序运行后位置任务栏位置上面 右键单击退出程序 左键单击翻页
解压密码:SDF234_zzcodes.net_DLS735 源码介绍:TINKPHP二次开发 糗事百科源码 ... 其它说明:以下程序完全采用TINKPHP开发! 在功能上也有查考某仿糗事百科上的一些技术。其次,TINKPHP完全开源,这点请放心使用。
程序安装: 输入 http://你的域名/install 按照提示填写 账号密码:admin admin888 安装完成后进入后台 系统 - 数据库备份/还原 - 数据还原 然后开始还原 还原后,先修改管理员密码。 注意: 用了一键更新之后...
基于DiscuzX系列开发的discuz高仿糗事百科网站源码,支持外链视频,外链图显示。
仿糗事百科,Hbuilding 多端输出.
你可以通过这种小偷程序,完成过去一些似乎完全不可能实现的任务,比如说把某个站的页面偷梁换柱后变成自己的页面,或者把某个站的一些数据(文章,图片)保存到本地数据库中加以利用。 “小偷程序”的优点. ...