java http://www.e-learn.cn/tag/java zh-hans 腾讯开源 iOS 内存监控组件和OOM检测工具 http://www.e-learn.cn/topic/4120872 <span>腾讯开源 iOS 内存监控组件和OOM检测工具</span> <span><span lang="" about="/user/47" typeof="schema:Person" property="schema:name" datatype="">谁说胖子不能爱</span></span> <span>2021-02-20 19:57:20</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <div class="rich_media_content" id="js_content"> <article class="" data-author="Wxeditor" style="margin: 5px auto;font-size: 16px;white-space: normal;color: rgb(62, 62, 62);border: 0px;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><section style="margin-right: auto;margin-left: auto;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><p style="margin: 0em 1em;padding: 10px;min-height: 1em;orphans: 2;widows: 2;text-align: justify;background-color: rgb(243, 243, 243);max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="font-size: 14px;color: rgb(102, 102, 102);font-family: 'Microsoft Yahei', Simsun, Gotham-Medium, Arial;line-height: 27px;background-color: rgb(243, 244, 245);max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;">自阿里巴巴开源Android检测内存泄露工具<a href="https://www.oschina.net/action/GoToLink?url=http%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzIyMjQ0MTU0NA%3D%3D%26mid%3D2247484053%26idx%3D1%26sn%3D7bc82aa66fda394c42a5e085507c307c%26chksm%3De82c3bb2df5bb2a44992765da6901f046f25642dd32c811b34dde4e0b584ec56ca5ce3358f29%26scene%3D21%23wechat_redirect" target="_blank" style="font-size: 14px;letter-spacing: 1px;line-height: 19px;white-space: normal;" rel="nofollow">LeakCanary</a>后,腾讯开源了一个在iOS 内存监控组件和一个OOM检测工具。</span></p> </section></article><p style="font-size: 16px;white-space: normal;min-height: 1em;color: rgb(62, 62, 62);max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><br style="max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;" /></p> <p style="text-align: center;margin-left: 16px;margin-right: 16px;"><img data-s="300,640" data-type="jpeg" src="https://oscimg.oschina.net/oscnet/fad280ea-e2f9-42be-9ba9-84aaa1f1034a.jpg" data-copyright="0" style="" class="" data-ratio="0.5625" data-w="480" /></p> <p style="white-space: normal;"><br /></p> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;"><br /></p> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;margin-left: 16px;margin-right: 16px;"><span style="color: rgb(0, 122, 170);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 20px;background-color: rgb(255, 255, 255);">MLeaksFinder </span></p> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="font-size: 15px;">MLeaksFinder 是腾讯开源的 iOS 平台的自动内存泄漏检测工具,引进 MLeaksFinder 后,就可以在日常的开发,调试业务逻辑的过程中自动地发现并警告内存泄漏。开发者无需打开 instrument 等工具,也无需为了找内存泄漏而去跑额外的流程。并且,由于开发者是在修改代码之后一跑业务逻辑就能发现内存泄漏的,这使得开发者能很快地意识到是哪里的代码写得问题。这种及时的内存泄漏的发现在很大的程度上降低了修复内存泄漏的成本。</span></p> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="box-sizing: border-box;font-size: 15px;">特性:</span></p> <ul class="list-paddingleft-2" style="margin-left: 16px;margin-right: 16px;"><li><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">自动检测内存泄漏和释放不及时的场景</span></p></li> <li><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">构建泄漏对象相对于 ViewContrller 的引用链以帮助开发者定位问题</span></p></li> <li><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">不侵入业务逻辑,引入即生效,无需修改任何代码或引入头文件</span></p></li> </ul><span id="OSC_h4_1"></span> <h4 style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;white-space: normal;margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="font-size: 15px;">用法</span></h4> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="font-size: 15px;">MLeaksFinder 可自动查找 UIView 和 UIViewController 对象中的泄漏。当发生泄漏时,它会在 View-ViewController 堆栈中显示泄漏对象预警。</span></p> <pre class="hljs lisp" style="box-sizing: border-box;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 13px;overflow-x: auto;padding: 10px;color: rgb(220, 220, 220);background-color: rgb(63, 63, 63);line-height: 1.4;word-wrap: normal;border-top-left-radius: 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;border-bottom-left-radius: 4px;"><code><p style="margin-left: 16px;margin-right: 16px;line-height: 2em;">Memory Leak (     <span class="hljs-name" style="box-sizing: border-box;color: rgb(239, 239, 143);">MyTableViewController</span>,     UITableView,     UITableViewWrapperView,     MyTableViewCell )</p></code></pre> <p><br /></p> <p style="margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="color: rgb(0, 122, 170);font-size: 20px;font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;">OOMDetector</span></p> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="font-size: 15px;">OOMDetector 是腾讯开源的一个 iOS 内存监控组件,应用此组件可以帮助你轻松实现 OOM 监控、大内存分配监控、内存泄漏检测等功能。<br style="box-sizing: border-box;" /></span></p> <p style="box-sizing: border-box;color: rgb(17, 17, 17);font-family: 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans CJK SC', Sathu, EucrosiaUPC, sans-serif;font-size: 16px;white-space: normal;margin-left: 16px;margin-right: 16px;line-height: 2em;"><span style="box-sizing: border-box;font-size: 15px;">组件特性:</span></p> <ul class="list-paddingleft-2" style="margin-left: 16px;margin-right: 16px;"><li><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">OOM监控</span></p><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">监控 OOM,Dump 引起爆内存的堆栈</span></p></li> <li><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">大内存分配监控</span></p><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">监控单次大块内存分配,提供分配堆栈信息</span></p></li> <li><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">内存泄漏检测</span></p><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;">可检测 OC 对象、Malloc 堆内存泄漏,提供泄漏堆栈信息</span></p><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;"></span></p><p style="box-sizing: border-box;line-height: 2em;"><span style="font-size: 15px;"></span></p></li> </ul><p><br /></p> <blockquote> <p style="margin-right: 16px;margin-left: 16px;font-size: 16px;white-space: normal;color: rgb(62, 62, 62);min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="color: rgb(136, 136, 136);font-size: 12px;line-height: 22px;">开发者技术前线 欢迎各界读者投稿,加群请回复“加群”,</span><br /></p> <p style="margin-right: 16px;margin-left: 16px;font-size: 16px;white-space: normal;color: rgb(62, 62, 62);min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="color: rgb(136, 136, 136);font-size: 12px;line-height: 22px;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;">免费小密圈请点击:</span><a href="https://www.oschina.net/action/GoToLink?url=http%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzUxMjUxMzIwNA%3D%3D%26mid%3D2247483725%26idx%3D2%26sn%3D3eb34c36db163e5c7c1dd6a2f5d419df%26chksm%3Df9620496ce158d80720a0430f6b8d75a309d2d8e86e289840a7af0ea1c917774a5d2e1d5afdb%26scene%3D21%23wechat_redirect" target="_blank" style="font-size: 12px;line-height: 22px;" rel="nofollow">这年头还有免费小密圈? 快加!</a></p> <p style="margin-right: 16px;margin-left: 16px;font-size: 16px;white-space: normal;color: rgb(62, 62, 62);min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="color: rgb(136, 136, 136);font-family: -apple-system, 'Helvetica Neue', Arial, 'PingFang SC', 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;font-size: 12px;font-weight: bold;line-height: 32px;text-align: center;">开发者技术前线 汇聚最新最热的技术干货,</span><span style="color: rgb(136, 136, 136);font-family: -apple-system, 'Helvetica Neue', Arial, 'PingFang SC', 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;font-size: 12px;font-weight: bold;line-height: 32px;text-align: center;">行业动态,职场思考, 热点思维,和一线面经!</span></p> </blockquote> <article class="" data-author="Wxeditor" style="margin: 5px auto;white-space: normal;color: rgb(62, 62, 62);letter-spacing: 1px;font-size: 14px;border: 0px;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><section style="margin-right: auto;margin-left: auto;padding: 10px;border-style: none;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><span style="margin-top: 15px;margin-left: -7px;float: left;display: block;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"> <section class="" style="margin-right: 10px;padding: 5px 8px;max-height: 30px;color: rgb(255, 255, 255);text-align: center;line-height: 1.5;font-size: 15px;min-width: 75px;background-color: rgb(29, 101, 174);max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"> 相关推荐 </section></span> <section style="padding: 16px;-webkit-box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 4px;box-shadow: rgba(0, 0, 0, 0.498039) 0px 0px 4px;line-height: 1.4;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><p style="min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><br /></p> <p style="min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><a href="https://www.oschina.net/action/GoToLink?url=http%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzIyMjQ0MTU0NA%3D%3D%26mid%3D2247484053%26idx%3D1%26sn%3D7bc82aa66fda394c42a5e085507c307c%26chksm%3De82c3bb2df5bb2a44992765da6901f046f25642dd32c811b34dde4e0b584ec56ca5ce3358f29%26scene%3D21%23wechat_redirect" target="_blank" rel="nofollow">LeakCanary- 如何检测 Activity 是否泄漏</a></p> <p style="min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><a href="https://www.oschina.net/action/GoToLink?url=http%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzIyMjQ0MTU0NA%3D%3D%26mid%3D2247484278%26idx%3D1%26sn%3D0ef2a50d797622b2d058a8d7ddb60034%26chksm%3De82c3a51df5bb3479dd2450f6365876942d2e41bea479ad33a4847484d657aec7ac54e6b2e51%26scene%3D21%23wechat_redirect" target="_blank" rel="nofollow">深入理解Java虚拟机--自动内存管理机制</a><br /></p> <p style="min-height: 1em;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><a href="https://www.oschina.net/action/GoToLink?url=http%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzIyMjQ0MTU0NA%3D%3D%26mid%3D2247484117%26idx%3D1%26sn%3D8de1fa939fe6f4d7db80389a716b6950%26chksm%3De82c3bf2df5bb2e4dae47f4082234dac39bbaee0028fc73d74840efdf3fc19d94931b3082750%26scene%3D21%23wechat_redirect" target="_blank" rel="nofollow">源码分析|Handler内存泄漏分析及解决</a></p> </section></section></article><article class="" data-author="Wxeditor" style="margin: 5px auto;font-size: 16px;white-space: normal;color: rgb(62, 62, 62);letter-spacing: 1px;line-height: 32px;border: 0px;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><blockquote class="__bg_gif" data-order="0" data-width="420px" data-wxsrc="http://mmbiz.qpic.cn/mmbiz/ianq03UUWGmKfVhVHzJZuMhn7fo97kMcmrewyA7N0JNrnWtZtIf3vqNkkE8Xxk1c2nZibwibcmSWjJuUib782IFMuQ/0?wx_fmt=gif" style="margin-right: auto;margin-left: auto;border: none rgb(255, 129, 36);width: 360px;background-image: url(http://mmbiz.qpic.cn/mmbiz_gif/Uic0S1r5o6OtdmnFm7joJfZFGKaHiavDLddFicCDQ4RdqfCic7600dcOEnibWjt9lvqhLicyuwXLtE3YwbDfU605KM0Q/s640?);background-size: contain;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;background-position: 100% 0px;background-repeat: no-repeat no-repeat;"> <section style="padding: 10px 3px;max-width: 100% !important;box-sizing: border-box !important;word-wrap: break-word !important;"><img border="0" class="" data-ratio="1" src="https://oscimg.oschina.net/oscnet/33116da6-2a34-4e10-b8d6-432a9adcc397.jpg" data-type="jpeg" data-w="258" data-width="150px" title="1488116844428059.jpg" vspace="0" width="150" style="max-width: 50% !important;box-sizing: border-box !important;word-wrap: break-word !important;width: auto !important;visibility: visible !important;" /></section></blockquote> </article></div> <p style="color: #858585; font-size: 13px;">本文分享自微信公众号 - 开发者技术前线(China_DevTech)。<br />如有侵权,请联系 support@oschina.cn 删除。<br />本文参与“<a href="https://www.oschina.net/sharing-plan" target="_blank" rel="nofollow">OSC源创计划</a>”,欢迎正在阅读的你也加入,一起分享。</p> <div class="alert alert-success" role="alert"><p>来源:<code>oschina</code></p><p>链接:<code>https://my.oschina.net/u/3071980/blog/4577980</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/mleaksfinder" hreflang="zh-hans">mleaksfinder</a></div> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/leakcanary" hreflang="zh-hans">leakcanary</a></div> <div class="field--item"><a href="/tag/oomdetector" hreflang="zh-hans">oomdetector</a></div> <div class="field--item"><a href="/tag/ios" hreflang="zh-hans">ios</a></div> <div class="field--item"><a href="/tag/uitableviewcell" hreflang="zh-hans">UITableViewCell</a></div> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> </div> </div> Sat, 20 Feb 2021 11:57:20 +0000 谁说胖子不能爱 4120872 at http://www.e-learn.cn 浅谈导出Execl的报表数据解决方案 http://www.e-learn.cn/topic/4120865 <span>浅谈导出Execl的报表数据解决方案</span> <span><span lang="" about="/user/30" typeof="schema:Person" property="schema:name" datatype="">☆樱花仙子☆</span></span> <span>2021-02-20 19:54:34</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <div class="rich_media_content" id="js_content"> <p style="text-align: center;"><img class="rich_pages js_insertlocalimg b-lazy" data-backh="211" data-backw="579" data-ratio="0.3648148148148148" data-s="300,640" data-type="jpeg" data-w="1080" style="width: 578px;height: 211px;" data-src="https://oscimg.oschina.net/oscnet/070c3ecb-2e68-4ba2-9eb8-3e86ce4349bb.jpg" data-original="https://oscimg.oschina.net/oscnet/070c3ecb-2e68-4ba2-9eb8-3e86ce4349bb.jpg" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p><span style="font-size: 15px;">项目中免不了要做一些数据导出功能,比如导出前一天的订单记录。涉及导出功能可大可小,根据系统具体的用户量、一天的订单量等情况。今天就讨论一下怎么设计一个合理的导出功能。<br /></span></p> <p><br /></p> <p><span style="font-size: 15px;"><strong>0x01:同步导出</strong></span></p> <p><span style="font-size: 15px;">这个方案最简单,就只需一个导出接口。这个接口只需实现根据用户条件到数据库查询相关数据,然后在应用程序中生成Execl电子表格,最后通过Response把生成的Execl电子表格回写到客户端即可<br /></span></p> <p style="text-align: center;"><img class="rich_pages b-lazy" data-ratio="0.5622280243690165" data-s="300,640" data-type="png" data-w="1149" style="" data-src="https://oscimg.oschina.net/oscnet/bacc06fb-159d-4421-9ab8-4152f370c19a.png" data-original="https://oscimg.oschina.net/oscnet/bacc06fb-159d-4421-9ab8-4152f370c19a.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p><span style="font-size: 15px;">该方案简单,因为是同步导出,所以不适用大量数据导出。如果使用该方案进行大量数据导出的话,存在客户端(浏览器)超时的情况,导致导出失败;因为浏览器与Nginx之间有超时设置。<br /></span></p> <p><br /></p> <p><span style="font-size: 15px;"><strong>0x02:异步导出</strong><br /></span></p> <p><span style="font-size: 15px;">异步导出一般需要设计三个接口。</span></p> <ul class="list-paddingleft-2" style="list-style-type: disc;"><li style="font-size: 15px;"><p><span style="font-size: 15px;">第一个接口:开启一个线程对进行数据查询,并对查询到的数据进行Execl电子表格读写操作,同步返回导出状态标识;</span></p></li> <li style="font-size: 15px;"><p><span style="font-size: 15px;">第二个接口:查询第一个接口的完成状态,如果完成Execl电子表格操作,则返回true;否则返回false;</span></p></li> <li style="font-size: 15px;"><p><span style="font-size: 15px;">第三个接口:根据第二个接口返回的状态,如果返回true,就调用下载Execl电子表格;否则返回false的话继续轮询调用第二个接口,直到返回true;</span></p></li> </ul><p style="text-align: center;"><img class="rich_pages b-lazy" data-ratio="0.7385892116182573" data-s="300,640" data-type="png" data-w="964" style="" data-src="https://oscimg.oschina.net/oscnet/0b82e934-dca7-41e7-abc6-67d20af246e0.png" data-original="https://oscimg.oschina.net/oscnet/0b82e934-dca7-41e7-abc6-67d20af246e0.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p><span style="font-size: 15px;">这种方案比较耗服务器性能,因为需要第二个接口轮询应用服务器的导出状态,设置一个比较合理的轮询周期显得非常必要。另外,第一种方案和第二种方案都没有对导出的结果进行存库记录,如果要下载同样的数据,要整个流程重新走一遍。这样的话就引出第三种方案。</span></p> <p><br /></p> <p><span style="font-size: 15px;"><strong>0x03:导出服务</strong><br /></span></p> <p><span style="font-size: 15px;">该方案需要一张表和两个接口。</span></p> <ul class="list-paddingleft-2" style="list-style-type: disc;"><li style="font-size: 15px;"><p><span style="font-size: 15px;">表的作用是用来存储谁进行了数据导出,导出的电子表格Execl存放的硬盘目录</span></p></li> <li style="font-size: 15px;"><p><span style="font-size: 15px;">第一个接口:开启一个线程对进行数据查询,并对查询到的数据进行Execl电子表格读写操作,最后把电子表格的目录存储到数据库;同步返回成功;</span></p></li> <li style="font-size: 15px;"><p><span style="font-size: 15px;">第二个接口:在导出列表中找出导出的记录,然后调用该接口进行Execl电子表格下载;<br /></span></p></li> </ul><p style="text-align: center;"><img class="rich_pages b-lazy" data-ratio="0.6810661764705882" data-s="300,640" data-type="png" data-w="1088" style="" data-src="https://oscimg.oschina.net/oscnet/b73c70a0-2535-4c7e-b302-58965e30c612.png" data-original="https://oscimg.oschina.net/oscnet/b73c70a0-2535-4c7e-b302-58965e30c612.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></p> <p><span style="font-size: 15px;">该方案需要额外做一个管理下载记录的界面,进行下载管理;这个方案的最大好处就是对下载操作进行了记录。如果需要对相同的数据导出,只需导出一遍即可。不过增加了存储的空间,无论数据库还是硬盘,都增加了。<br /></span></p> <p><br /></p> <p><span style="font-size: 15px;">在实际项目中使用哪种方案,根据具体业务场景,具体选择即可。其他文件类型的导出方案也可以参考该文章的方案进行操作。<br /></span></p> <section data-tools="135编辑器" data-id="91511" data-xmt-x1="501.5" data-xmt-y1="2078.578125" data-xmt-x2="1178.5" data-xmt-y2="2327.578125" style="max-width: 100%;box-sizing: border-box;font-variant-numeric: normal;font-variant-east-asian: normal;letter-spacing: 0.544px;line-height: 27.2px;white-space: normal;widows: 1;border-width: 0px;border-style: none;border-color: initial;background-color: rgb(255, 255, 255);overflow-wrap: break-word !important;"><section data-role="paragraph" data-xmt-x1="501.5" data-xmt-y1="2253.578125" data-xmt-x2="1178.5" data-xmt-y2="2327.578125" style="max-width: 100%;box-sizing: border-box;border-width: 0px;border-style: none;border-color: initial;overflow-wrap: break-word !important;"><section data-width="100%" data-xmt-x1="501.5" data-xmt-y1="2253.578125" data-xmt-x2="1178.5" data-xmt-y2="2327.578125" style="margin: 5px auto;max-width: 100%;width: 677px;text-align: right;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;display: inline-block;width: auto;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;display: -webkit-flex;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section data-xmt-x1="754.5" data-xmt-y1="2273.578125" data-xmt-x2="874.5" data-xmt-y2="2327.578125" style="margin-top: 20px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;display: inline-block;width: auto;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section data-xmt-x1="754.5" data-xmt-y1="2273.578125" data-xmt-x2="874.5" data-xmt-y2="2327.578125" style="max-width: 100%;text-align: left;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section data-tools="135编辑器" data-id="94250" data-xmt-x1="501.5" data-xmt-y1="2429.78125" data-xmt-x2="1178.5" data-xmt-y2="2492.78125" style="max-width: 100%;box-sizing: border-box;border-width: 0px;border-style: none;border-color: initial;overflow-wrap: break-word !important;"><section data-tools="135编辑器" data-id="91842" data-xmt-x1="501.5" data-xmt-y1="2429.78125" data-xmt-x2="1178.5" data-xmt-y2="2492.78125" style="max-width: 100%;box-sizing: border-box;border-width: 0px;border-style: none;border-color: initial;overflow-wrap: break-word !important;"><section data-xmt-x1="501.5" data-xmt-y1="2429.78125" data-xmt-x2="1178.5" data-xmt-y2="2492.78125" style="max-width: 100%;text-align: right;width: auto;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section style="max-width: 100%;display: inline-block;clear: both;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section data-brushtype="text" data-xmt-x1="868" data-xmt-y1="2429.78125" data-xmt-x2="1153.5" data-xmt-y2="2454.78125" style="padding: 18px 15px 20px 10px;max-width: 100%;box-sizing: border-box;color: rgb(86, 146, 214);text-align: center;font-size: 16px;letter-spacing: 1.5px;background-image: url(&quot;https://oscimg.oschina.net/oscnet/297b1a8c-87e1-40ce-8dd3-f687d40415fb.png&quot;);background-size: 100% 100%;background-repeat: no-repeat;overflow-wrap: break-word !important;"><section style="max-width: 100%;display: flex;justify-content: center;align-items: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"><section data-xmt-x1="880" data-xmt-y1="2447.78125" data-xmt-x2="900" data-xmt-y2="2472.78125" style="margin-left: 2px;max-width: 100%;width: 20px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><img data-ratio="0.8936170212765957" data-type="png" data-w="47" style="margin-bottom: -6px;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 20px !important;" class="b-lazy" data-src="https://oscimg.oschina.net/oscnet/3aba27e8-4b7c-4fcf-ad0a-1f6ad62a521b.png" data-original="https://oscimg.oschina.net/oscnet/3aba27e8-4b7c-4fcf-ad0a-1f6ad62a521b.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></section><p data-xmt-x1="900" data-xmt-y1="2449.28125" data-xmt-x2="1163.5" data-xmt-y2="2471.28125" style="max-width: 100%;min-height: 1em;font-size: 14px;color: rgb(51, 51, 51);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="font-size: 15px;">喜欢,在看</span></p> <p data-xmt-x1="1163.5" data-xmt-y1="2449.28125" data-xmt-x2="1163.5" data-xmt-y2="2471.28125" style="max-width: 100%;min-height: 1em;font-size: 14px;color: rgb(51, 51, 51);box-sizing: border-box !important;overflow-wrap: break-word !important;"><br /></p> </section></section></section></section></section></section></section></section></section></section></section></section></section></section><p><br /></p> </div> <p style="color: #858585; font-size: 13px;">本文分享自微信公众号 - JAVA乐园(happyhuangjinjin88)。<br />如有侵权,请联系 support@oschina.cn 删除。<br />本文参与“<a href="https://www.oschina.net/sharing-plan" target="_blank" rel="nofollow">OSC源创计划</a>”,欢迎正在阅读的你也加入,一起分享。</p> <div class="alert alert-success" role="alert"><p>来源:<code>oschina</code></p><p>链接:<code>https://my.oschina.net/u/3385288/blog/4957995</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/nginx" hreflang="zh-hans">nginx</a></div> </div> </div> Sat, 20 Feb 2021 11:54:34 +0000 ☆樱花仙子☆ 4120865 at http://www.e-learn.cn Java ---- 遍历链表(递归与非递归实现) http://www.e-learn.cn/topic/4120829 <span>Java ---- 遍历链表(递归与非递归实现)</span> <span><span lang="" about="/user/55" typeof="schema:Person" property="schema:name" datatype="">风格不统一</span></span> <span>2021-02-20 19:30:13</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <div class="cnblogs_code"> <pre><code><span style="color: #0000ff;">package</span><span style="color: #000000;"> test; </span><span style="color: #008000;">//</span><span style="color: #008000;">前序遍历的递归实现与非递归实现</span> <span style="color: #0000ff;">import</span><span style="color: #000000;"> java.util.Stack; </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Test { </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> main(String[] args) { TreeNode[] node </span>= <span style="color: #0000ff;">new</span> TreeNode[10];<span style="color: #008000;">//</span><span style="color: #008000;">以数组形式生成一棵完全二叉树</span> <span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i = 0; i &lt; 10; i++<span style="color: #000000;">) { node[i] </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> TreeNode(i); } </span><span style="color: #0000ff;">for</span>(<span style="color: #0000ff;">int</span> i = 0; i &lt; 10; i++<span style="color: #000000;">) { </span><span style="color: #0000ff;">if</span>(i*2+1 &lt; 10<span style="color: #000000;">) node[i].left </span>= node[i*2+1<span style="color: #000000;">]; </span><span style="color: #0000ff;">if</span>(i*2+2 &lt; 10<span style="color: #000000;">) node[i].right </span>= node[i*2+2<span style="color: #000000;">]; } preOrderRe(node[</span>0<span style="color: #000000;">]); } </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> preOrderRe(TreeNode biTree) {</span><span style="color: #008000;">//</span><span style="color: #008000;">递归实现</span> <span style="color: #000000;"> System.out.println(biTree.value); TreeNode leftTree </span>=<span style="color: #000000;"> biTree.left; </span><span style="color: #0000ff;">if</span>(leftTree != <span style="color: #0000ff;">null</span><span style="color: #000000;">) { preOrderRe(leftTree); } TreeNode rightTree </span>=<span style="color: #000000;"> biTree.right; </span><span style="color: #0000ff;">if</span>(rightTree != <span style="color: #0000ff;">null</span><span style="color: #000000;">) { preOrderRe(rightTree); } } </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> preOrder(TreeNode biTree) {</span><span style="color: #008000;">//</span><span style="color: #008000;">非递归实现</span> Stack&lt;TreeNode&gt; stack = <span style="color: #0000ff;">new</span> Stack&lt;TreeNode&gt;<span style="color: #000000;">(); </span><span style="color: #0000ff;">while</span>(biTree != <span style="color: #0000ff;">null</span> || !<span style="color: #000000;">stack.isEmpty()) { </span><span style="color: #0000ff;">while</span>(biTree != <span style="color: #0000ff;">null</span><span style="color: #000000;">) { System.out.println(biTree.value); stack.push(biTree); biTree </span>=<span style="color: #000000;"> biTree.left; } </span><span style="color: #0000ff;">if</span>(!<span style="color: #000000;">stack.isEmpty()) { biTree </span>=<span style="color: #000000;"> stack.pop(); biTree </span>=<span style="color: #000000;"> biTree.right; } } } } </span><span style="color: #0000ff;">class</span> TreeNode<span style="color: #008000;">//</span><span style="color: #008000;">节点结构</span> <span style="color: #000000;">{ </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> value; TreeNode left; TreeNode right; TreeNode(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> value) { </span><span style="color: #0000ff;">this</span>.value =<span style="color: #000000;"> value; } }</span></code></pre> </div> <p> </p> <p><strong>二叉树的遍历</strong></p> <p><strong>二叉树的遍历分为三种:前序遍历 中序遍历 后序遍历</strong></p> <p> </p> <p>前序遍历:按照“根左右”,先遍历根节点,再遍历左子树 ,再遍历右子树</p> <p>中序遍历:按照“左根右“,先遍历左子树,再遍历根节点,最后遍历右子树</p> <p>后续遍历:按照“左右根”,先遍历左子树,再遍历右子树,最后遍历根节点 </p> <p>其中前,后,中指的是每次遍历时候的根节点被遍历的顺序 </p> <p> </p> <p><strong>二叉树遍历:</strong></p> <p><strong>前根左右</strong></p> <p><strong>中左根右</strong></p> <p><strong>后左右根</strong></p> <p> </p> <div class="alert alert-success" role="alert"><p>来源:<code>oschina</code></p><p>链接:<code>https://my.oschina.net/u/4374409/blog/3563229</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> </div> </div> Sat, 20 Feb 2021 11:30:13 +0000 风格不统一 4120829 at http://www.e-learn.cn Java程序员养成日记一(计算机基础)2.20 http://www.e-learn.cn/topic/4120825 <span>Java程序员养成日记一(计算机基础)2.20</span> <span><span lang="" about="/user/227" typeof="schema:Person" property="schema:name" datatype="">烂漫一生</span></span> <span>2021-02-20 19:28:29</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"> <span id="OSC_h1_1"></span> <h1>参照博客<a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fblog.csdn.net%2Fqq_23851075%2Farticle%2Fdetails%2F55807658" rel="nofollow" target="_blank">java程序员技能树</a>(如有侵权马上删除)</h1> <span id="OSC_h1_2"></span> <h1><strong>经典回顾</strong></h1> <ul><li> <span id="OSC_h2_3"></span><h2><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E6%2593%258D%25E4%25BD%259C%25E7%25B3%25BB%25E7%25BB%259F%2F192%3Ffr%3Daladdin" rel="nofollow" target="_blank">操作系统( <span style="background-color:#ffffff; color:#333333">operation system</span>  OS)</a></h2> </li> </ul><ol><li> <span id="OSC_h4_4"></span><h4>简介</h4> </li> </ol><p><span style="background-color:#ffffff; color:#333333">操作系统(operation system,简称OS)是管理</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA%25E7%25A1%25AC%25E4%25BB%25B6%2F5459592" target="_blank" rel="nofollow">计算机硬件</a><span style="background-color:#ffffff; color:#333333">与</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25BD%25AF%25E4%25BB%25B6%2F12053" target="_blank" rel="nofollow">软件</a><span style="background-color:#ffffff; color:#333333">资源的</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA%25E7%25A8%258B%25E5%25BA%258F%2F3220205" target="_blank" rel="nofollow">计算机程序</a><span style="background-color:#ffffff; color:#333333">。操作系统需要处理如管理与配置</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E5%2586%2585%25E5%25AD%2598%2F103614" target="_blank" rel="nofollow">内存</a><span style="background-color:#ffffff; color:#333333">、决定</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25B3%25BB%25E7%25BB%259F%25E8%25B5%2584%25E6%25BA%2590%2F974435" target="_blank" rel="nofollow">系统资源</a><span style="background-color:#ffffff; color:#333333">供需的优先次序、控制</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25BE%2593%25E5%2585%25A5%25E8%25AE%25BE%25E5%25A4%2587%2F10823368" target="_blank" rel="nofollow">输入设备</a><span style="background-color:#ffffff; color:#333333">与</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25BE%2593%25E5%2587%25BA%25E8%25AE%25BE%25E5%25A4%2587%2F10823333" target="_blank" rel="nofollow">输出设备</a><span style="background-color:#ffffff; color:#333333">、操作网络与管理文件系统等基本事务。操作系统也提供一个让用户与系统交互的操作界面。</span></p> <ul><li> <span id="OSC_h4_5"></span><h4>主要的操作系统</h4> </li> </ul><ol><li> <p style="text-align:start">嵌入式( <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FVxWorks" target="_blank" rel="nofollow">VxWorks</a><span style="background-color:#ffffff; color:#333333">、</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FeCos" target="_blank" rel="nofollow">eCos</a><span style="background-color:#ffffff; color:#333333">、</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FSymbian%2520OS" target="_blank" rel="nofollow">Symbian OS</a><span style="background-color:#ffffff; color:#333333">及</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FPalm%2520OS" target="_blank" rel="nofollow">Palm OS</a>、 <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FiOS%2F45705" target="_blank" rel="nofollow">iOS</a> 、 <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FAndroid%2F60243" target="_blank" rel="nofollow">Android</a> )</p> </li> <li> <p style="text-align:start">类 Unix( <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FSystem%2520V" target="_blank" rel="nofollow">System V</a><span style="background-color:#ffffff; color:#333333">、</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FBSD" target="_blank" rel="nofollow">BSD</a><span style="background-color:#ffffff; color:#333333">与</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FLinux" target="_blank" rel="nofollow">Linux</a> )</p> </li> <li> <p style="text-align:start">Microsoft Windows( <span style="background-color:#ffffff; color:#333333">Windows XP</span> 、 <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FWindows%25207%2F1083761" target="_blank" rel="nofollow">Windows 7</a> 、 <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FWindows%252010%2F6877791" target="_blank" rel="nofollow">Windows 10</a> 、)</p> </li> <li> <p style="text-align:start">MacOS X( <a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2FMacOS" target="_blank" rel="nofollow">MacOS</a><span style="background-color:#ffffff; color:#333333">和MacOS X</span> )</p> </li> <li> <p style="text-align:start">Google Chrome OS( <span style="background-color:#ffffff; color:#333333">Google的轻型的、基于网络的计算机操作系统计划</span> )</p> </li> </ol><p> </p> <ul><li> <span id="OSC_h2_6"></span><h2><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25BC%2596%25E8%25AF%2591%25E5%258E%259F%25E7%2590%2586%2F4194%3Ffr%3Daladdin%233" rel="nofollow" target="_blank">编译原理</a></h2> </li> <li><img alt="编译原理框架" class="b-lazy" data-src="https://img-blog.csdn.net/20150326173504251" data-original="https://img-blog.csdn.net/20150326173504251" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /></li> </ul><ol><li> <span id="OSC_h4_7"></span><h4>基本概念</h4> </li> </ol><p><span style="background-color:#ffffff; color:#333333">编译原理即是对高级程序语言进行翻译的一门科学技术, 我们都知道计算机程序由</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25A8%258B%25E5%25BA%258F%25E8%25AF%25AD%25E8%25A8%2580%2F10696489" target="_blank" rel="nofollow">程序语言</a><span style="background-color:#ffffff; color:#333333">编写而成, 在早期计算机程序语言发展较为缓慢, 因为计算机存储的数据和执行的程序都是由0、1代码组合而成的, 那么在早期程序员编写计算机程序时必须十分了解计算机的底层指令代码通过将这些微程序指令组合排列从而完成一个特定功能的程序, 这就对程序员的要求非常高了。人们一直在研究如何如何高效的开发计算机程序, 使编程的门槛降低。</span></p> <ol><li> <span id="OSC_h4_8"></span><h4>编译器</h4> </li> </ol><p><span style="background-color:#ffffff; color:#333333">编译过程一般是在计算机系统中实现的, 是将源代码转化为计算机通用语言的过程。</span></p> <ol><li> <span id="OSC_h4_9"></span><h4>编译的基本流程</h4> </li> </ol><p><span style="background-color:#ffffff; color:#333333">编译可以分为五个基本步骤:词法分析、语法分析、</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25AF%25AD%25E4%25B9%2589%25E5%2588%2586%25E6%259E%2590%2F8853372" target="_blank" rel="nofollow">语义分析</a><span style="background-color:#ffffff; color:#333333">及</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E4%25B8%25AD%25E9%2597%25B4%25E4%25BB%25A3%25E7%25A0%2581%2F10934909" target="_blank" rel="nofollow">中间代码</a><span style="background-color:#ffffff; color:#333333">的生成、优化、目标代码的生成。这是每个编译器都必须的基本步骤和流程, 从源头输入高级语言源程序输出目标语言代码。</span></p> <ol><li><span style="background-color:#ffffff; color:#333333">词法分析</span> ( <span style="background-color:#ffffff; color:#333333">词法分析程序或词法分析器或扫描器</span> )</li> <li><span style="background-color:#ffffff; color:#333333">语法分析</span> ( <span style="background-color:#ffffff; color:#333333">语法规则又称为文法, 分为0型、1型、2型、3型文法, 0型文法又称短语文法, 1型称为上下文有关文法, 2型称为上下文无关文法, 3型文法称为正规文法, 限制条件依次递增。</span> 判断语法规则)</li> <li><span style="background-color:#ffffff; color:#333333">语义分析</span> ( <span style="background-color:#ffffff; color:#333333">词法分析注重的是每个单词是否合法, 以及这个单词属于语言中的哪些部分</span> )</li> <li><span style="background-color:#ffffff; color:#333333">中间代码生成与优化</span> ( <span style="background-color:#ffffff; color:#333333">所谓“中间代码”是一种结构简单、含义明确的记号系统, 这种记号系统复杂性介于源程序语言和机器语言之间, 容易将它翻译成目标代码。</span>)</li> <li><span style="background-color:#ffffff; color:#333333">目标代码的生成</span> ( <span style="background-color:#ffffff; color:#333333">根据优化后的中间代码, 可生成有效的目标代码。而通常编译器将其翻译为汇编代码, 此时还需要将汇编代码经汇编器汇编为目标机器的机器语言</span> )</li> <li><span style="background-color:#ffffff; color:#333333">出错处理</span> ( <span style="background-color:#ffffff; color:#333333">编译的各个阶段都有可能发现源码中的错误, 尤其是语法分析阶段可能会发现大量的错误, 因此编译器需要做出错处理, 报告错误类型及错误位置等信息</span> )</li> </ol><p> </p> <ul><li> <span id="OSC_h2_10"></span><h2><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA%25E7%25BD%2591%25E7%25BB%259C%2F18763%3Ffr%3Daladdin" rel="nofollow" target="_blank">计算机网络</a>( <span style="background-color:#ffffff; color:#333333">computer networks</span> )</h2> </li> <li> <span id="OSC_h4_11"></span><h4>定义(简介)</h4> </li> </ul><p><span style="background-color:#ffffff; color:#333333">计算机网络是指将</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E5%259C%25B0%25E7%2590%2586" target="_blank" rel="nofollow">地理</a><span style="background-color:#ffffff; color:#333333">位置不同的具有独立功能的多台</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA%2F140338" target="_blank" rel="nofollow">计算机</a><span style="background-color:#ffffff; color:#333333">及其外部设备,通过通信线路连接起来,在</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25BD%2591%25E7%25BB%259C%25E6%2593%258D%25E4%25BD%259C%25E7%25B3%25BB%25E7%25BB%259F%2F3997" target="_blank" rel="nofollow">网络操作系统</a><span style="background-color:#ffffff; color:#333333">,</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25BD%2591%25E7%25BB%259C%25E7%25AE%25A1%25E7%2590%2586%25E8%25BD%25AF%25E4%25BB%25B6%2F6579078" target="_blank" rel="nofollow">网络管理软件</a><span style="background-color:#ffffff; color:#333333">及</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25BD%2591%25E7%25BB%259C%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%2F4438611" target="_blank" rel="nofollow">网络通信协议</a><span style="background-color:#ffffff; color:#333333">的管理和协调下,实现</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25B5%2584%25E6%25BA%2590%25E5%2585%25B1%25E4%25BA%25AB%2F233480" target="_blank" rel="nofollow">资源共享</a><span style="background-color:#ffffff; color:#333333">和信息传递的计算机系统。</span></p> <p> </p> <ol><li> <p style="text-align:start">按广义( <span style="background-color:#ffffff; color:#333333">一些相互连接的、以</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E5%2585%25B1%25E4%25BA%25AB%25E8%25B5%2584%25E6%25BA%2590" target="_blank" rel="nofollow">共享资源</a><span style="background-color:#ffffff; color:#333333">为目的的</span> 、 <span style="background-color:#ffffff; color:#333333">自治的计算机的集合。</span> <span style="background-color:#ffffff; color:#333333">从</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E9%2580%25BB%25E8%25BE%2591" target="_blank" rel="nofollow">逻辑</a><span style="background-color:#ffffff; color:#333333">功能上看,计算机网络是以传输信息为</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E5%259F%25BA%25E7%25A1%2580" target="_blank" rel="nofollow">基础</a><span style="background-color:#ffffff; color:#333333">目的,用</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E9%2580%259A%25E4%25BF%25A1%25E7%25BA%25BF%25E8%25B7%25AF" target="_blank" rel="nofollow">通信线路</a><span style="background-color:#ffffff; color:#333333">将多个计算机连接起来的计算机系统的集合,一个计算机网络组成包括</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E4%25BC%25A0%25E8%25BE%2593%25E4%25BB%258B%25E8%25B4%25A8" target="_blank" rel="nofollow">传输介质</a><span style="background-color:#ffffff; color:#333333">和</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E9%2580%259A%25E4%25BF%25A1%25E8%25AE%25BE%25E5%25A4%2587" target="_blank" rel="nofollow">通信设备</a><span style="background-color:#ffffff; color:#333333">。</span> )</p> </li> <li> <p style="text-align:start">按连接(<span style="background-color:#ffffff; color:#333333">计算机网络就是通过线路互连起来的、自治的计算机集合,确切的说就是将分布在不同地理位置上的具有独立工作能力的计算机、</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E7%25BB%2588%25E7%25AB%25AF" target="_blank" rel="nofollow">终端</a><span style="background-color:#ffffff; color:#333333">及其附属设备用通信设备和</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E9%2580%259A%25E4%25BF%25A1" target="_blank" rel="nofollow">通信</a><span style="background-color:#ffffff; color:#333333">线路连接起来,并配置网络</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25BD%25AF%25E4%25BB%25B6" target="_blank" rel="nofollow">软件</a><span style="background-color:#ffffff; color:#333333">,以实现计算机资源共享的系统。</span> )</p> </li> <li> <p style="text-align:start">按需求( <span style="background-color:#ffffff; color:#333333">计算机网络就是由大量独立的、但相互连接起来的计算机来共同完成</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E8%25AE%25A1%25E7%25AE%2597%25E6%259C%25BA" target="_blank" rel="nofollow">计算机</a><span style="background-color:#ffffff; color:#333333">任务。这些系统称为计算机网络(computer networks)</span> )</p> </li> </ol><p> </p> <ul><li> <span id="OSC_h4_12"></span><h4>组成</h4> </li> </ul><p><span style="background-color:#ffffff; color:#333333">计算机网络的分类与一般的事物分类方法一样,可以按事物所具有的不同性质特点(即事物的属性)分类。计算机网络通俗地讲就是由多台计算机(或其它计算机网络设备)通过传输介质和软件物理(或逻辑)连接在一起组成的。总的来说计算机网络的组成基本上包括:计算机、网络操作系统、传输介质(可以是有形的,也可以是无形的,如无线网络的传输介质就是空间)以及相应的应用软件四部分。</span></p> <p> </p> <ul><li> <span id="OSC_h4_13"></span><h4>功能</h4> </li> </ul><ol><li> <p style="text-align:start">数据通信<br /><span style="background-color:#ffffff; color:#333333">数据通信是计算机网络的最主要的功能之一。数据通信是依照一定的通信协议,利用数据传输技术在两个终端之间传递数据信息的一种通信方式和通信业务</span></p> </li> <li> <p>资源共享<br /><span style="background-color:#ffffff; color:#333333">资源共享是人们建立计算机网络的主要目的之一。计算机资源包括硬件资源、软件资源和数据资源。</span> (避免设备、大型数据库等的重复建设)</p> </li> <li> <p style="text-align:start"> </p> <p>集中管理<br /><span style="background-color:#ffffff; color:#333333">计算机网络技术的发展和应用,已使得现代的办公手段、经营管理等发生了变化</span></p> <p> </p> </li> <li>实现分布式处理<br /><span style="background-color:#ffffff; color:#333333">网络技术的发展,使得分布式计算成为可能。对于大型的课题,可以分为许许多多小题目,由不同的计算机分别完成,然后再集中起来,解决问题。</span></li> <li>负载均衡<br /><span style="background-color:#ffffff; color:#333333">负荷均衡是指工作被均匀的分配给网络上的各台计算机系统。网络控制中心负责分配和检测,当某台计算机负荷过重时,系统会自动转移负荷到较轻的计算机系统去处理。</span></li> </ol><p><span style="background-color:#ffffff; color:#333333">评价:由此可见,计算机网络可以大大扩展计算机系统的功能,扩大其应用范围,提高可靠性,为用户提供方便,同时也减少了费用,提高了性能价格比。</span></p> <ul><li> <span id="OSC_h4_14"></span><h4>分类</h4> </li> </ul><ol><li>局域网 <span style="background-color:#ffffff; color:#333333">(Local Area Network;LAN)</span><br /><span style="background-color:#ffffff; color:#333333">局域网一般位于一个建筑物或一个单位内,不存在寻径问题,不包括网络层的应用。</span></li> <li>城域网 <span style="background-color:#ffffff; color:#333333">(Metropolitan Area Network;MAN)</span><br /><span style="background-color:#ffffff; color:#333333">一般在政府城域网中应用,如邮政、银行、医院等。</span></li> <li>广域网 <span style="background-color:#ffffff; color:#333333">(Wide Area Network,WAN)<span> </span></span><br /><span style="background-color:#ffffff; color:#333333">邮电部的CHINANET,CHINAPAC,和CHINADDN网。</span></li> <li>无线网<br /><span style="background-color:#ffffff; color:#333333">无线通信系统主要有:低功率的无绳电话系统、模拟蜂窝系统、数字蜂窝系统、移动卫星系统、无线LAN和无线WAN等。</span></li> </ol><ul><li> <span id="OSC_h4_15"></span><h4>性能</h4> </li> </ul><p><span style="background-color:#ffffff; color:#333333">计算机网络的性能一般是指它的几个重要的性能指标。但除了这些重要的性能指标外,还有一些非性能特征,它们对计算机网络的性能也有很大的影响。</span></p> <ol><li>计算机网络的性能指标<br /><span style="background-color:#ffffff; color:#333333">性能指标从不同的方面来度量计算机网络的性能。</span><br />          <span style="background-color:#ffffff; color:#333333">(1)速率</span><br />                  <span style="background-color:#ffffff; color:#333333">计算机发送出的信号都是数字形式的。比特是计算机中数据量的单位,也是信息论中使用的信息量的单位。</span><br />          <span style="background-color:#ffffff; color:#333333">(2)带宽</span><br />                  <span style="background-color:#ffffff; color:#333333">① 带宽本来是指某个信号具有的频带宽度。信号的带宽是指该信号所包含的各种不同频率成分所占据的频率范围。例如,在传统的通信线路上传送的电话信号的标准带宽是3.1kHz(从300Hz到3.4kHz,即话音的主要成分的频率范围)。这种意义的带宽的单位是赫(或千赫,兆赫,吉赫等)。</span><br />                  <span style="background-color:#ffffff; color:#333333">② 在计算机网络中,带宽用来表示网络的通信线路所能传送数据的能力,因此网络带宽表示在单位时间内从网络中的某一点到另一点所能通过的“最高数据率”。这里一般说到的“带宽”就是指这个意思。这种意义的带宽的单位是“比特每秒”,记为bit/s。</span><br />          <span style="background-color:#ffffff; color:#333333">(3)吞吐量</span><br />                  <span style="background-color:#ffffff; color:#333333">吞吐量表示在单位时间内通过某个网络(或信道、接口)的数据量。吞吐量更经常地用于对现实世界中的网络的一种测量,以便知道实际上到底有多少数据量能够通过网络。</span><br />          <span style="background-color:#ffffff; color:#333333">(4)时延</span><br /><span style="background-color:#ffffff; color:#333333">发送时延是主机或路由器发送数据帧所需要的时间,也就是从发送数据帧的第一个比特算起,到该帧的最后一个比特发送完毕所需的时间。</span><br />                  <span style="background-color:#ffffff; color:#333333">① 发送时延。</span><br />                               <span style="background-color:#ffffff; color:#333333">发送时延的计算公式是:</span><br />                  <span style="background-color:#ffffff; color:#333333">② 传播时延。</span><br />                               <span style="background-color:#ffffff; color:#333333">传播时延是电磁波在信道中传播一定的距离需要花费的时间。传播时延的计算公式是:</span><br />                               <span style="color:#e74c3c"><span style="background-color:#ffffff">传播时延=信道长度(m)/电磁波在信道上的传播速率(m/s)</span> </span><br />                               <span style="background-color:#ffffff; color:#333333">电磁波在自由空间的传播速率是光速,即300000km/s。电磁波在网络传输媒体中的传播速率比在自由空间要略低一些。</span><br />                  <span style="background-color:#ffffff; color:#333333">③ 处理时延。</span><br />                               <span style="background-color:#ffffff; color:#333333">主机或路由器在收到分组时要花费一定的时间进行处理,例如分析分组的首部,从分组中提取数据部分,进行差错检验或查找适当的路由等,这就产生了处理时延。</span><br />                  <span style="background-color:#ffffff; color:#333333">④ 排队时延。</span><br />                              ​​​​​​​ <span style="background-color:#ffffff; color:#333333">分组在经过网络传输时,要经过许多的路由器。但分组在进入路由器后要先在输入队列中排队等待处理。在路由器确定了转发接口后,还要在输出队列中排队等待转发。这就产生了排队时延。</span><br />                              ​​​​​​​ <span style="background-color:#ffffff; color:#333333">数据在网络中经历的总时延就是以上四种时延之和:</span><br />                              ​​​​​​​ <span style="color:#e74c3c">总时延=发送时延+传播时延+处理时延+排队时延 </span></li> <li>计算机网络的非性能特征<br /><span style="background-color:#ffffff; color:#333333">这些非性能特征与前面介绍的性能指标有很大的关系。</span><br />          <span style="background-color:#ffffff; color:#333333">(1)费用</span><br />                  <span style="background-color:#ffffff; color:#333333">即网络的价格(包括设计和实现的费用)。网络的性能与其价格密切相关。一般说来,网络的速率越高,其价格也越高。</span><br />          <span style="background-color:#ffffff; color:#333333">(2)质量</span><br />                  <span style="background-color:#ffffff; color:#333333">网络的质量取决于网络中所有构件的质量,以及这些构件是怎样组成网络的。网络的质量影响到很多方面,如网络的可靠性、网络管理的简易性,以及网络的一些性能</span> (网络质量与价格成正比 ,<span style="background-color:#ffffff; color:#333333">高质量的网络往往价格也较高</span> )<br />          <span style="background-color:#ffffff; color:#333333">(3)标准化</span><br />                  <span style="background-color:#ffffff; color:#333333">网络的硬件和软件的设计既可以按照通用的国际标准,也可以遵循特定的专用网络标准。最好采用国际标准的设计,这样可以得到更好的互操作性,更易于升级换代和维修,也更容易得到技术上的支持。</span><br />          <span style="background-color:#ffffff; color:#333333">(4)可靠性</span><br />                  <span style="background-color:#ffffff; color:#333333">可靠性与网络的质量和性能都有密切关系。速率更高的网络,其可靠性不一定会更差。但速率更高的网络要可靠地运行,则往往更加困难,同时所需的费用也会较高。</span><br />          <span style="background-color:#ffffff; color:#333333">(5)可扩展性和可升级性</span><br />                  <span style="background-color:#ffffff; color:#333333">网络在构造时就应当考虑到今后可能会需要扩展(即规模扩大)和升级(即性能和版本的提高)。网络的性能越高,其扩展费用往往也越高,难度也会相应增加。</span><br />          <span style="background-color:#ffffff; color:#333333">(6)易于管理和维护</span><br />                  <span style="background-color:#ffffff; color:#333333">网络如果没有良好的管理和维护,就很难达到和保持所设计的性能。</span></li> </ol><ul><li> <span id="OSC_h2_16"></span><h2><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E4%25BA%2592%25E8%2581%2594%25E7%25BD%2591%25E5%258D%258F%25E8%25AE%25AE%2F6492810%3Ffr%3Daladdin" rel="nofollow" target="_blank">互联网协议</a>​​​​​​​( <span style="background-color:#ffffff; color:#333333">Internet Protocol Suite</span> )</h2> </li> </ul><p><span style="background-color:#ffffff; color:#333333">IP是互联网协议群(Internet Protocol Suite ,IPS)中众多</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E9%2580%259A%25E4%25BF%25A1%25E5%258D%258F%25E8%25AE%25AE%2F3351624" target="_blank" rel="nofollow">通信协议</a><span style="background-color:#ffffff; color:#333333">中的一个,也是其中最重要的一个。IP 协议属于通信协议中的第三层网络层协议,完成路由寻址和消息传递的功能。专家们一般将IPS解释为一个协议</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E5%25A0%2586%25E6%25A0%2588%2F1682032" target="_blank" rel="nofollow">堆栈</a><span style="background-color:#ffffff; color:#333333">,它可以将应用程序的信息(比如电子邮件或者网页传输的内容)转换为网络可以传输的</span><a href="https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fbaike.baidu.com%2Fitem%2F%25E6%2595%25B0%25E6%258D%25AE%25E5%258C%2585%2F489739" target="_blank" rel="nofollow">数据包</a><span style="background-color:#ffffff; color:#333333">。</span></p> <p> </p> <div class="alert alert-success" role="alert"><p>来源:<code>oschina</code></p><p>链接:<code>https://my.oschina.net/u/4207792/blog/4957877</code></p></div></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/mac-os-x" hreflang="zh-hans">Mac OS X</a></div> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/chrome-os" hreflang="zh-hans">Chrome OS</a></div> <div class="field--item"><a href="/tag/vxworks" hreflang="zh-hans">VxWorks</a></div> <div class="field--item"><a href="/tag/linux" hreflang="zh-hans">Linux</a></div> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/ios" hreflang="zh-hans">ios</a></div> <div class="field--item"><a href="/tag/ecos" hreflang="zh-hans">ecos</a></div> <div class="field--item"><a href="/tag/symbian" hreflang="zh-hans">symbian</a></div> </div> </div> Sat, 20 Feb 2021 11:28:29 +0000 烂漫一生 4120825 at http://www.e-learn.cn Try-catch creates infinite loop [duplicate] http://www.e-learn.cn/topic/4120755 <span>Try-catch creates infinite loop [duplicate]</span> <span><span lang="" about="/user/150" typeof="schema:Person" property="schema:name" datatype="">只谈情不闲聊</span></span> <span>2021-02-20 19:08:39</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell wmn0 fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt4"> Endless while loop problem with try/catch <span class="question-originals-answer-count"> (2 answers) </span> </div> <div class="grid--cell mb0 mt8">Closed <span title="2015-12-15 15:50:36Z" class="relativetime">5 years ago</span>.</div> </div> </aside></div> <p>I need to be able to take user input until the input is greater than the initial price, but I also need to make it robust so that the user can't break the program by entering something other than a double/integer. If the user does enter something other than a double/int.</p> <p>The problem is that it creates a loop and repeats "Please enter valid currency" + "Please enter: price"</p> <pre><code> public static double findChange() { System.out.println("\nPlease insert: " + price + " (enter payment amount)"); initialPrice = price; while (payment &lt; price) { try{ payment = kb.nextDouble(); } catch (Exception e) { System.out.println("Please enter valid currency"); } if (payment &gt; 0){ totalPayment += payment; price -= payment; price = (price * 100); payment = 0; } if (totalPayment &lt; initialPrice) System.out.println("Please Insert:" + price); } change = totalPayment - initialPrice; change = Math.round(change * 100); change = change / 100; System.out.println("\nChange Given: $" + change); return change; } </code></pre> <br /><h3>回答1:</h3><br /><p>The reason you're seeing an infinite loop is that you never clear the invalid entry out of the input. If you look at the docs, it says</p> <blockquote> <p><strong>If the translation is successful</strong>, the scanner advances past the input that matched. </p> </blockquote> <p>When it fails, you should call <code>kb.next()</code> to remove the input that did not match a double, so that you can move on to the next user entry. Otherwise, you'll keep trying to parse the same invalid text over and over:</p> <pre><code>catch (Exception e) { System.out.println("Please enter valid currency"); kb.next(); } </code></pre> <p>A few other things you can improve as well. There's no need to be using a <code>try</code> and <code>catch</code> here, since you can use the <code>hasNextDouble</code> method to check that the input is valid. If you do decide to stick with exception handling though, you should catch <code>InputMismatchException</code> rather than a generic <code>Exception</code>, or else you risk running into some more problems (for example, if the input gets exhausted). You can also put a <code>continue</code> in when the input fails, so that it doesn't evaluate the rest of the code which is assuming that you correctly read a value.</p> <pre><code>if(kb.hasNextDouble()){ payment = kb.nextDouble(); } else{ System.out.println("Please enter valid currency"); kb.next(); continue; } </code></pre> <p>Note that there's still a problem with your logic, and the loop will never exit (since <code>payment</code> always gets reset to zero). I assume you want to do <code>totalPayment &lt; price</code> instead.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Since you want it to recognize any input, but only use doubles, try <code>Double.parseDouble(String)</code>. I also moved the rest of the logic to your try block, since it should only occur when valid input is received. If it can't parse the double, it breaks out without attempting the rest of the logic and tries again.</p> <pre><code>while (payment &lt; price &amp;&amp; price &gt; 0){ try{ payment = Double.parseDouble(kb.next()); if (payment &gt; 0){ totalPayment += payment; price -= payment; price = (price * 100); payment = 0; } if (totalPayment &lt; initialPrice){ System.out.println("Please Insert:" + price); } } catch (Exception e) { System.out.println("Please enter valid currency"); } } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/34292881/try-catch-creates-infinite-loop</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/try-catch" hreflang="zh-hans">try-catch</a></div> <div class="field--item"><a href="/tag/infinite-loop" hreflang="zh-hans">infinite-loop</a></div> </div> </div> Sat, 20 Feb 2021 11:08:39 +0000 只谈情不闲聊 4120755 at http://www.e-learn.cn visualvm - Local java applications cannot be detected http://www.e-learn.cn/topic/4120699 <span>visualvm - Local java applications cannot be detected</span> <span><span lang="" about="/user/184" typeof="schema:Person" property="schema:name" datatype="">柔情痞子</span></span> <span>2021-02-20 18:55:23</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am trying to run visualvm in my Windows 8 machine and i am getting error 'Local java applications cannot be detected'. I tried to follow the below steps to resolve the issue as suggested in 'https://visualvm.github.io/troubleshooting.html'. I gave full permission to my 'AppData\Local\Temp\hsperfdata_Dhasan' folder. But still i am getting the same error whenever i start visualvm. Please help me to fix this issue.</p> <p>Thanks.</p> <br /><h3>回答1:</h3><br /><p>Quit all java applications and delete <code>hsperfdata_Dhasan</code> folder.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/49160051/visualvm-local-java-applications-cannot-be-detected</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/visualvm" hreflang="zh-hans">VisualVM</a></div> <div class="field--item"><a href="/tag/jvisualvm" hreflang="zh-hans">jvisualvm</a></div> </div> </div> Sat, 20 Feb 2021 10:55:23 +0000 柔情痞子 4120699 at http://www.e-learn.cn Dynamic programming problems solution to interleaving strings http://www.e-learn.cn/topic/4120678 <span>Dynamic programming problems solution to interleaving strings</span> <span><span lang="" about="/user/235" typeof="schema:Person" property="schema:name" datatype="">你。</span></span> <span>2021-02-20 18:52:08</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I was trying to solve this problem, and I gave up, and found the solution below, although I do not understand how the solution works, or why it works. Any in-depth solution would be deeply appreciated.</p> <p>Question:</p> <blockquote> <p>Given <code>s1</code>, <code>s2</code>, <code>s3</code>, find whether <code>s3</code> is formed by the interleaving of <code>s1</code> and <code>s2</code>.</p> <p>For example, Given:</p> <pre><code>s1 = "aabcc" s2 = "dbbca" </code></pre> <ul><li>When <code>s3 = "aadbbcbcac"</code>, return true.</li> <li>When <code>s3 = "aadbbbaccc"</code>, return false.</li> </ul></blockquote> <p>Solution:</p> <pre><code> public static boolean isInterleave(String s1, String s2, String s3) { if (s3.length() == 0 &amp;&amp; s1.length() == 0 &amp;&amp; s2.length() == 0) return true; else if (s3.length() != s1.length() + s2.length()) return false; boolean isInter[][] = new boolean[s1.length()+1][s2.length()+1]; isInter[0][0] = true; for ( int i = 1; i &lt;= s1.length(); ++i){ if (s1.charAt(i-1) == s3.charAt(i-1)) isInter[i][0] = true; else break; } for ( int i = 1; i &lt;= s2.length(); ++i){ if (s2.charAt(i-1) == s3.charAt(i-1)) isInter[0][i] = true; else break; } // DP for ( int i = 1; i &lt;= s1.length(); ++i){ for ( int j = 1; j &lt;= s2.length(); ++j){ if (s3.charAt(i+j-1) == s1.charAt(i-1)) isInter[i][j] = isInter[i-1][j] || isInter[i][j]; if (s3.charAt(i+j-1) == s2.charAt(j-1)) isInter[i][j] = isInter[i][j-1] || isInter[i][j]; } } return isInter[s1.length()][s2.length()]; } </code></pre> <br /><h3>回答1:</h3><br /><p>I'm using Python slice syntax here because it is nice. <code>S[:-1]</code> means the string <code>S</code> with its last character removed and <code>S[:n]</code> means the prefix of <code>S</code> that has length <code>n</code>.</p> <p>The key idea is that if <code>C</code> is an interleaving of <code>A</code> and <code>B</code>, then <code>C[:-1]</code> is either an interleaving of <code>A</code> and <code>B[:-1]</code> or of <code>A[:-1]</code> and <code>B</code>. On the other hand, if <code>C</code> is an interleaving of <code>A</code> and <code>B</code>, then <code>C + 'X'</code> is an interleaving of <code>A + 'X'</code> and <code>B</code> and it is also an interleaving of <code>A</code> and <code>B + 'X'</code>.</p> <p>These are the substructure properties we need to apply dynamic programming. </p> <p>We define <code>f(i, j) = true</code>, if <code>s1[:i]</code> and <code>s2[:j]</code> can be interleaved to form <code>s3[:(i+j)]</code> and <code>f(i,j) = false</code> otherwise. By the observation above we have</p> <pre><code>f(0,0) = true f(i,0) = f(i-1, 0) if s3[i-1] == s1[i-1] f(0,j) = f(0, j-1) if s3[j-1] == s2[j-1] f(i,j) = true if s3[i+j-1] = s1[i-1] and f(i-1, j) f(i,j) = true if s3[i+j-1] = s2[j-1] and f(i, j-1) </code></pre> <p>In all the other cases we have <code>f(i,j) = false</code>. The Java code just implements this recurrence using dynamic programming. That said, I would implement it in a bit more concise way:</p> <pre><code>for (int i = 0; i &lt;= s1.length(); ++i) for (int j = 0; j &lt;= s2.length(); ++j) isInter[i][j] = (i == 0 &amp;&amp; j == 0) || (i &gt; 0 &amp;&amp; s1.charAt(i-1) == s3.charAt(i+j-1) &amp;&amp; isInter[i-1][j]) || (j &gt; 0 &amp;&amp; s2.charAt(j-1) == s3.charAt(i+j-1) &amp;&amp; isInter[i][j-1]); </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>The first few lines just deal with simple cases that can be resolved based only on the input string lengths. These tests simplify the remaining code by allowing it to assume that the lengths match.</p> <p>The guts of the algorithm calculate an array <code>isInter</code>, where <code>isInter[i][j]</code> is true after iteration <code>(i,j)</code> if, and only if, the first <code>i+j</code> characters of <code>s3</code> can be formed by interleaving the first <code>i</code> characters of <code>s1</code> with the first <code>j</code> characters of <code>s2</code>.</p> <p><code>isInter[i][0]</code> is true if, and only if, the first <code>i</code> characters of <code>s3</code> match the first <code>i</code> characters of <code>s1</code>. Similarly, <code>isInter[0][i]</code> is true if, and only if, the first <code>i</code> characters of <code>s3</code> match the first <code>i</code> characters of <code>s2</code>.</p> <p>The final loop builds up the remaining elements of isInter using already calculated elements and matches between the next character of <code>s3</code> and either the next character of <code>s1</code> or the next character of <code>s2</code>.</p> <p>After <code>isInter</code> has been completely calculated, <code>isInter[s1.length()][s2.length()]</code> is true if, and only if, the whole of <code>s3</code> can be formed by interleaving the whole of <code>s1</code> with the whole of <code>s2</code>.</p> <br /><br /><br /><h3>回答3:</h3><br /><p>Here is another attempt to show how the code works, using extremely plain syntax in C++. Their are some inline comments in the code for you to understand. It can't get simpler than this :)</p> <pre><code>//using dynamic programming : O(n^2) bool is_interleaved_On2_DP(string s1, string s2, string s3) { bool ret = false; int len1 = s1.length(); int len2 = s2.length(); int len3 = s3.length(); if( len1 + len2 != len3 ) { return ret; } #define M(i, j) match[ (i) * len1 + (j) ] //bool match[len1 + 1][len2 + 1]; //todo; use dynamic allocation bool* match = new bool[ (len1+1)*(len2+1) ]; int i, j, k; /* init match table to be all false */ for( i = 0; i &lt;= len1; i++ ) { for( j = 0; j &lt;= len2; j++ ) { M(i, j) = false; } } /* init match[0][0] == true */ M(0, 0) = true; //why ? null is interleaving 2 other nulls :) /* init the s1 side of table i.e. column */ for( i = 1; i &lt;= len1; i++ ) { char c1 = s1[i - 1]; char c3 = s3[i - 1]; if(c1 == c3) { M(i, 0) = true; } else { break; } } /* init the s2 side of table i.e. row */ for( j = 1; j &lt;= len2; j++ ) { char c2 = s2[j - 1]; char c3 = s3[j - 1]; if(c2 == c3) { M(0, j) = true; } else { break; } } /* compute remaining table */ for( i = 1; i &lt;= len1; i++ ) { char c1 = s1[i - 1]; for( j = 1; j &lt;= len2; j++ ) { char c2 = s2[j - 1]; int k = i + j; //index for s3 char c3 = s3[k - 1]; if(c1 == c3) { M(i, j) = M(i - 1, j) || M(i, j); } if(c2 == c3) { M(i, j) = M(i, j - 1) || M(i, j); } } } ret = M(len1, len2); delete [] match; #undef M return ret; } </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/22795589/dynamic-programming-problems-solution-to-interleaving-strings</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/algorithm" hreflang="zh-hans">algorithm</a></div> </div> </div> Sat, 20 Feb 2021 10:52:08 +0000 你。 4120678 at http://www.e-learn.cn Programmatically update certificates in tomcat 8 without server restart http://www.e-learn.cn/topic/4120658 <span>Programmatically update certificates in tomcat 8 without server restart</span> <span><span lang="" about="/user/136" typeof="schema:Person" property="schema:name" datatype="">扶醉桌前</span></span> <span>2021-02-20 18:50:10</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>In order to update the certificate that I use for SSL for my server I have a code that does the import\export and validation that I need.</p> <p>It works well, but In order for the changes to take effect I have to restart the tomcat.<br /> I wish to avoid the restart, and update it without using external tools (keytool for example).<br /> I looked up for some similar questions, and found a solution - restarting the 443 connector. I'm able to do so, and the connector is stopping and starting, but the certificate was not updated. Only server restart actually updates it. </p> <p>Is there some connector initialisation procedure that I'm missing?<br /> Some system cache or objects that I should clear?</p> <p>This is the code that I use for restarting the connector: </p> <pre><code>MBeanServer mbeanServer = null; ObjectName objectName = null; final ObjectName objectNameQuery = new ObjectName("*:type=Connector,port=443,*"); for (final MBeanServer server : (ArrayList&lt;MBeanServer&gt;) MBeanServerFactory.findMBeanServer(null)) { if (server.queryNames(objectNameQuery, null).size() &gt; 0) { mbeanServer = server; objectName = (ObjectName) server.queryNames(objectNameQuery,null).toArray()[0]; break; } } mbeanServer.invoke(objectName, "stop", null, null); Thread.sleep(1000); mbeanServer.invoke(objectName, "start", null, null); </code></pre> <p>I see in the tomcat logs the following traces of the connector restart:<br /><code>23-Apr-2017 15:42:00.292 INFO [BG-Task RestartTomcatConnector] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-443"]</code><br /><code>23-Apr-2017 15:42:01.349 INFO [BG-Task RestartTomcatConnector] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-443"]</code></p> <br /><h3>回答1:</h3><br /><p>The problem was solved, these are the components:</p> <ol><li><p>server.xml must include <code>bindOnInit="false"</code>. This is the config I use</p> <pre><code>&lt;Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="443" SSLEnabled="true" maxThreads="150" acceptCount="2000" scheme="https" secure="true" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_RSA_WITH_AES_256_CBC_SHA" keystoreFile="webapps/ServerKeyStore" keystorePass="***" clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1.1,TLSv1.2" compression="on" compressableMimeType="text/html,text/xml,application/xml,application/json,application/javascript,text/css,text/plain" server="Portal" useSendfile="false" compressionMinSize="1024" bindOnInit="false" /&gt; </code></pre></li> <li><p>The Java code for the connector restart: </p> <pre><code>public class TomcatConnectorRestarter implements Callable&lt;Boolean&gt; { private final int waitSeconds = 3; private final static ReentrantLock rl = new ReentrantLock(); @Override public Boolean call() throws Exception { restartConnector(); return true; } protected void restartConnector() throws Exception { try { if (tryLock()){ mLogger.info("Acquired lock"); try { HTTPSConnectorMBean httpsConnector = null; MBeanServer mbeanServer = null; ObjectName objectName = null; final ObjectName objectNameQuery = new ObjectName("*:type=Connector,port=443,*"); for (final MBeanServer server : (ArrayList&lt;MBeanServer&gt;) MBeanServerFactory.findMBeanServer(null)) { if (server.queryNames(objectNameQuery, null).size() &gt; 0) { mbeanServer = server; objectName = (ObjectName) server.queryNames(objectNameQuery, null).toArray()[0]; httpsConnector = new HTTPSConnectorMBean(objectName, mbeanServer); break; } } if (Objects.nonNull(httpsConnector)) { mLogger.info("Stopping connector"); httpsConnector.stop(); mLogger.info("Waiting "+waitSeconds+" seconds after "+"stop"+" ..."); Thread.sleep(waitSeconds*1000); mLogger.info("Starting connector"); httpsConnector.start(); } else { mLogger.error("Could not find connector object"); } } catch (Exception e) { mLogger.error("Failed restarting connector",e); } } else { mLogger.warn("Operation is in process"); } } finally { unlock(); } } private void unlock() { if (rl.isHeldByCurrentThread()) { mLogger.debug("Releasing lock"); rl.unlock(); } } private boolean tryLock() { return !rl.isHeldByCurrentThread() &amp;&amp; rl.tryLock(); } private enum MBeanConnectorAction { start,stop,getState; } private abstract class MBeansObjectAction { private final ObjectName on; private final MBeanServer server; public MBeansObjectAction(ObjectName on, MBeanServer server) { this.on = on; this.server = server; } protected Object invoke(MBeanConnectorAction cmd) throws InstanceNotFoundException, ReflectionException, MBeanException { return server.invoke(on, cmd.toString(), null, null); } } private class HTTPSConnectorMBean extends MBeansObjectAction { public HTTPSConnectorMBean(ObjectName on, MBeanServer server) { super(on, server); } public void start() throws InstanceNotFoundException, ReflectionException, MBeanException { invoke(MBeanConnectorAction.start); } public void stop() throws InstanceNotFoundException, ReflectionException, MBeanException { invoke(MBeanConnectorAction.stop); } public Object status() throws InstanceNotFoundException, ReflectionException, MBeanException { return invoke(MBeanConnectorAction.getState); } } } </code></pre></li> </ol><br /><br /><p>来源:<code>https://stackoverflow.com/questions/43571572/programmatically-update-certificates-in-tomcat-8-without-server-restart</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/tomcat" hreflang="zh-hans">Tomcat</a></div> <div class="field--item"><a href="/tag/ssl" hreflang="zh-hans">ssl</a></div> <div class="field--item"><a href="/tag/certificate" hreflang="zh-hans">certificate</a></div> <div class="field--item"><a href="/tag/mbeans" hreflang="zh-hans">mbeans</a></div> </div> </div> Sat, 20 Feb 2021 10:50:10 +0000 扶醉桌前 4120658 at http://www.e-learn.cn sonarqube 6.3 error could-not-complete-symbolic-execution-reached-limit-of-16000 steps http://www.e-learn.cn/topic/4120651 <span>sonarqube 6.3 error could-not-complete-symbolic-execution-reached-limit-of-16000 steps</span> <span><span lang="" about="/user/192" typeof="schema:Person" property="schema:name" datatype="">谁都会走</span></span> <span>2021-02-20 18:48:34</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We have a scan that aborts on the code below, with the exception:</p> <pre><code>org.sonar.java.se.ExplodedGraphWalker$MaximumStepsReachedException: reached limit of 16000 steps for method getServiceProviders#151 in class ServiceProviderService </code></pre> <p>We looked at rules S2259 and S2583 and would like to keep notifications about null pointers. </p> <p>This happens in both "regular" and debug (-X) mode, so it's not issue 1406. In our case it really seems to be related to try/catch. (See sample method below.) Could it be a resurgence of issue 1295? https://jira.sonarsource.com/browse/SONARJAVA-1295 If so, is there a way to simply increase the stack from 16,000 so that we can move along?</p> <h1>SAMPLE METHOD:</h1> <pre><code>public static List&lt;ServiceProvider&gt; getServiceProviders() throws DAOException { Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; List&lt;ServiceProvider&gt; serviceProviderList = new ArrayList&lt;&gt;(); try { con = DatabaseUtils.getConnection(); if (con != null) { stmt = con.prepareStatement(sqlSelectServiceProviders); rs = stmt.executeQuery(); while (rs.next()) { ServiceProvider serviceProvider = new ServiceProvider(); serviceProvider.setId(rs.getLong(1)); serviceProvider.setName(rs.getString(2)); // etc. serviceProviderList.add(serviceProvider); } } else { DAOException ourDAOException = new DAOException(); ourDAOException.setMessageCode(Consts.ERROR_CANNOT_ESTABLISH_CONNECTIONS); throw ourDAOException; } } catch (DAOException daoexcep) { throw daoexcep; } catch (Exception sqlex) { log.error(ErrorType.SYSTEM + ": " + Consts.ERROR_CANNOT_GET_SERVICE_PROVIDER + " - " + sqlex); log.error(sqlex); try { if (con != null) { con.rollback(); } } catch (SQLException ex) { } DAOException ourDAOException = new DAOException(sqlex); ourDAOException.setMessageCode(Consts.ERROR_CANNOT_GET_SERVICE_PROVIDER); throw ourDAOException; } finally { if (con != null) { try { con.close(); } catch (SQLException e) { } con = null; } } return serviceProviderList; } </code></pre> <br /><h3>回答1:</h3><br /><p>6.3 and later require Oracle Java 8. Our public Java 7 seems to be the most likely culprit. The actual cause might have been something else, but the upgrade fixed it.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/43189650/sonarqube-6-3-error-could-not-complete-symbolic-execution-reached-limit-of-16000</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/sonarqube" hreflang="zh-hans">sonarqube</a></div> <div class="field--item"><a href="/tag/try-catch-finally" hreflang="zh-hans">try-catch-finally</a></div> </div> </div> Sat, 20 Feb 2021 10:48:34 +0000 谁都会走 4120651 at http://www.e-learn.cn sonarqube 6.3 error could-not-complete-symbolic-execution-reached-limit-of-16000 steps http://www.e-learn.cn/topic/4120642 <span>sonarqube 6.3 error could-not-complete-symbolic-execution-reached-limit-of-16000 steps</span> <span><span lang="" about="/user/226" typeof="schema:Person" property="schema:name" datatype="">泄露秘密</span></span> <span>2021-02-20 18:47:14</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>We have a scan that aborts on the code below, with the exception:</p> <pre><code>org.sonar.java.se.ExplodedGraphWalker$MaximumStepsReachedException: reached limit of 16000 steps for method getServiceProviders#151 in class ServiceProviderService </code></pre> <p>We looked at rules S2259 and S2583 and would like to keep notifications about null pointers. </p> <p>This happens in both "regular" and debug (-X) mode, so it's not issue 1406. In our case it really seems to be related to try/catch. (See sample method below.) Could it be a resurgence of issue 1295? https://jira.sonarsource.com/browse/SONARJAVA-1295 If so, is there a way to simply increase the stack from 16,000 so that we can move along?</p> <h1>SAMPLE METHOD:</h1> <pre><code>public static List&lt;ServiceProvider&gt; getServiceProviders() throws DAOException { Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; List&lt;ServiceProvider&gt; serviceProviderList = new ArrayList&lt;&gt;(); try { con = DatabaseUtils.getConnection(); if (con != null) { stmt = con.prepareStatement(sqlSelectServiceProviders); rs = stmt.executeQuery(); while (rs.next()) { ServiceProvider serviceProvider = new ServiceProvider(); serviceProvider.setId(rs.getLong(1)); serviceProvider.setName(rs.getString(2)); // etc. serviceProviderList.add(serviceProvider); } } else { DAOException ourDAOException = new DAOException(); ourDAOException.setMessageCode(Consts.ERROR_CANNOT_ESTABLISH_CONNECTIONS); throw ourDAOException; } } catch (DAOException daoexcep) { throw daoexcep; } catch (Exception sqlex) { log.error(ErrorType.SYSTEM + ": " + Consts.ERROR_CANNOT_GET_SERVICE_PROVIDER + " - " + sqlex); log.error(sqlex); try { if (con != null) { con.rollback(); } } catch (SQLException ex) { } DAOException ourDAOException = new DAOException(sqlex); ourDAOException.setMessageCode(Consts.ERROR_CANNOT_GET_SERVICE_PROVIDER); throw ourDAOException; } finally { if (con != null) { try { con.close(); } catch (SQLException e) { } con = null; } } return serviceProviderList; } </code></pre> <br /><h3>回答1:</h3><br /><p>6.3 and later require Oracle Java 8. Our public Java 7 seems to be the most likely culprit. The actual cause might have been something else, but the upgrade fixed it.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/43189650/sonarqube-6-3-error-could-not-complete-symbolic-execution-reached-limit-of-16000</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/sonarqube" hreflang="zh-hans">sonarqube</a></div> <div class="field--item"><a href="/tag/try-catch-finally" hreflang="zh-hans">try-catch-finally</a></div> </div> </div> Sat, 20 Feb 2021 10:47:14 +0000 泄露秘密 4120642 at http://www.e-learn.cn