⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toethread.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="150" href="#150">150</a>                     setCurrentCuri(curi);<a name="151" href="#151">151</a>                 }<a name="152" href="#152">152</a>                 <a name="153" href="#153">153</a>                 processCrawlUri();<a name="154" href="#154">154</a>                 <a name="155" href="#155">155</a>                 setStep(STEP_ABOUT_TO_RETURN_URI);<a name="156" href="#156">156</a>                 continueCheck();<a name="157" href="#157">157</a> <a name="158" href="#158">158</a>                 <strong>synchronized</strong>(<strong>this</strong>) {<a name="159" href="#159">159</a>                     controller.getFrontier().finished(currentCuri);<a name="160" href="#160">160</a>                     setCurrentCuri(<strong>null</strong>);<a name="161" href="#161">161</a>                 }<a name="162" href="#162">162</a>                 <a name="163" href="#163">163</a>                 setStep(STEP_FINISHING_PROCESS);<a name="164" href="#164">164</a>                 lastFinishTime = System.currentTimeMillis();<a name="165" href="#165">165</a>                 controller.releaseContinuePermission();<a name="166" href="#166">166</a>                 <strong>if</strong>(shouldRetire) {<a name="167" href="#167">167</a>                     <strong>break</strong>; <em class="comment">// from while(true)</em><a name="168" href="#168">168</a>                 }<a name="169" href="#169">169</a>             }<a name="170" href="#170">170</a>         } <strong>catch</strong> (EndedException e) {<a name="171" href="#171">171</a>             <em class="comment">// crawl ended (or thread was retired), so allow thread to end</em><a name="172" href="#172">172</a>         } <strong>catch</strong> (Exception e) {<a name="173" href="#173">173</a>             <em class="comment">// everything else (including interruption)</em><a name="174" href="#174">174</a>             logger.log(Level.SEVERE,<span class="string">"Fatal exception in "</span>+getName(),e);<a name="175" href="#175">175</a>         } <strong>catch</strong> (OutOfMemoryError err) {<a name="176" href="#176">176</a>             seriousError(err);<a name="177" href="#177">177</a>         } <strong>finally</strong> {<a name="178" href="#178">178</a>             controller.releaseContinuePermission();<a name="179" href="#179">179</a>         }<a name="180" href="#180">180</a>         setCurrentCuri(<strong>null</strong>);<a name="181" href="#181">181</a>         <em class="comment">// Do cleanup so that objects can be GC.</em><a name="182" href="#182">182</a>         <strong>this</strong>.httpRecorder.closeRecorders();<a name="183" href="#183">183</a>         <strong>this</strong>.httpRecorder = <strong>null</strong>;<a name="184" href="#184">184</a>         localProcessors = <strong>null</strong>;<a name="185" href="#185">185</a> <a name="186" href="#186">186</a>         logger.fine(getName()+<span class="string">" finished for order '"</span>+name+<span class="string">"'"</span>);<a name="187" href="#187">187</a>         setStep(STEP_FINISHED);<a name="188" href="#188">188</a>         controller.toeEnded();<a name="189" href="#189">189</a>         controller = <strong>null</strong>;<a name="190" href="#190">190</a>     }<a name="191" href="#191">191</a> <a name="192" href="#192">192</a>     <em>/**<em>*</em></em><a name="193" href="#193">193</a> <em>     * Set currentCuri, updating thread name as appropriate</em><a name="194" href="#194">194</a> <em>     * @param curi</em><a name="195" href="#195">195</a> <em>     */</em><a name="196" href="#196">196</a>     <strong>private</strong> <strong>void</strong> setCurrentCuri(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="197" href="#197">197</a>         <strong>if</strong>(curi==<strong>null</strong>) {<a name="198" href="#198">198</a>             setName(coreName);<a name="199" href="#199">199</a>         } <strong>else</strong> {<a name="200" href="#200">200</a>             setName(coreName+curi);<a name="201" href="#201">201</a>         }<a name="202" href="#202">202</a>         currentCuri = curi;<a name="203" href="#203">203</a>     }<a name="204" href="#204">204</a> <a name="205" href="#205">205</a>     <em>/**<em>*</em></em><a name="206" href="#206">206</a> <em>     * @param s</em><a name="207" href="#207">207</a> <em>     */</em><a name="208" href="#208">208</a>     <strong>private</strong> <strong>void</strong> setStep(String s) {<a name="209" href="#209">209</a>         step=s;<a name="210" href="#210">210</a>         atStepSince = System.currentTimeMillis();<a name="211" href="#211">211</a>     }<a name="212" href="#212">212</a> <a name="213" href="#213">213</a> 	<strong>private</strong> <strong>void</strong> seriousError(Error err) {<a name="214" href="#214">214</a> 	    <em class="comment">// try to prevent timeslicing until we have a chance to deal with OOM</em><a name="215" href="#215">215</a>         <em class="comment">// TODO: recognize that new JVM priority indifference may make this</em><a name="216" href="#216">216</a>         <em class="comment">// priority-jumbling pointless</em><a name="217" href="#217">217</a>         setPriority(DEFAULT_PRIORITY+1);  <a name="218" href="#218">218</a>         <strong>if</strong> (controller!=<strong>null</strong>) {<a name="219" href="#219">219</a>             <em class="comment">// hold all ToeThreads from proceeding to next processor</em><a name="220" href="#220">220</a>             controller.singleThreadMode();<a name="221" href="#221">221</a>             <em class="comment">// TODO: consider if SoftReferences would be a better way to </em><a name="222" href="#222">222</a>             <em class="comment">// engineer a soft-landing for low-memory conditions</em><a name="223" href="#223">223</a>             controller.freeReserveMemory();<a name="224" href="#224">224</a>             controller.requestCrawlPause();<a name="225" href="#225">225</a>             <strong>if</strong> (controller.getFrontier().getFrontierJournal() != <strong>null</strong>) {<a name="226" href="#226">226</a>                 controller.getFrontier().getFrontierJournal().seriousError(<a name="227" href="#227">227</a>                     getName() + err.getMessage());<a name="228" href="#228">228</a>             }<a name="229" href="#229">229</a>         }<a name="230" href="#230">230</a>         <a name="231" href="#231">231</a>         <em class="comment">// OutOfMemory etc.</em><a name="232" href="#232">232</a>         String extraInfo = DevUtils.extraInfo();<a name="233" href="#233">233</a>         System.err.println(<span class="string">"&lt;&lt;&lt;"</span>);<a name="234" href="#234">234</a>         System.err.println(ArchiveUtils.getLog17Date());<a name="235" href="#235">235</a>         System.err.println(err);<a name="236" href="#236">236</a>         System.err.println(extraInfo);<a name="237" href="#237">237</a>         err.printStackTrace(System.err);<a name="238" href="#238">238</a>         <a name="239" href="#239">239</a>         <strong>if</strong> (controller!=<strong>null</strong>) {<a name="240" href="#240">240</a>             PrintWriter pw = <strong>new</strong> PrintWriter(System.err);<a name="241" href="#241">241</a>             controller.getToePool().compactReportTo(pw);<a name="242" href="#242">242</a>             pw.flush();<a name="243" href="#243">243</a>         }<a name="244" href="#244">244</a>         System.err.println(<span class="string">">>>"</span>);<a name="245" href="#245">245</a> <em class="comment">//        DevUtils.sigquitSelf();</em><a name="246" href="#246">246</a>         <a name="247" href="#247">247</a>         String context = <span class="string">"unknown"</span>;<a name="248" href="#248">248</a> 		<strong>if</strong>(currentCuri!=<strong>null</strong>) {<a name="249" href="#249">249</a>             <em class="comment">// update fetch-status, saving original as annotation</em><a name="250" href="#250">250</a>             currentCuri.addAnnotation(<span class="string">"err="</span>+err.getClass().getName());<a name="251" href="#251">251</a>             currentCuri.addAnnotation(<span class="string">"os"</span>+currentCuri.getFetchStatus());<a name="252" href="#252">252</a> 			currentCuri.setFetchStatus(S_SERIOUS_ERROR);<a name="253" href="#253">253</a>             context = currentCuri.singleLineReport() + <span class="string">" in "</span> + currentProcessorName;<a name="254" href="#254">254</a> 		}<a name="255" href="#255">255</a>         String message = <span class="string">"Serious error occured trying "</span> +<a name="256" href="#256">256</a>             <span class="string">"to process '"</span> + context + <span class="string">"'\n"</span> + extraInfo;<a name="257" href="#257">257</a>         logger.log(Level.SEVERE, message.toString(), err);<a name="258" href="#258">258</a>         setPriority(DEFAULT_PRIORITY);<a name="259" href="#259">259</a> 	}<a name="260" href="#260">260</a> <a name="261" href="#261">261</a> 	<em>/**<em>*</em></em><a name="262" href="#262">262</a> <em>     * Perform checks as to whether normal execution should proceed.</em><a name="263" href="#263">263</a> <em>     * </em><a name="264" href="#264">264</a> <em>     * If an external interrupt is detected, throw an interrupted exception.</em><a name="265" href="#265">265</a> <em>     * Used before anything that should not be attempted by a 'zombie' thread</em><a name="266" href="#266">266</a> <em>     * that the Frontier/Crawl has given up on.</em><a name="267" href="#267">267</a> <em>     * </em><a name="268" href="#268">268</a> <em>     * Otherwise, if the controller's memoryGate has been closed,</em><a name="269" href="#269">269</a> <em>     * hold until it is opened. (Provides a better chance of </em><a name="270" href="#270">270</a> <em>     * being able to complete some tasks after an OutOfMemoryError.)</em><a name="271" href="#271">271</a> <em>     *</em><a name="272" href="#272">272</a> <em>     * @throws InterruptedException</em><a name="273" href="#273">273</a> <em>     */</em><a name="274" href="#274">274</a>     <strong>private</strong> <strong>void</strong> continueCheck() throws InterruptedException {<a name="275" href="#275">275</a>         <strong>if</strong>(Thread.interrupted()) {<a name="276" href="#276">276</a>             <strong>throw</strong> <strong>new</strong> InterruptedException(<span class="string">"die request detected"</span>);<a name="277" href="#277">277</a>         }<a name="278" href="#278">278</a>         controller.acquireContinuePermission();<a name="279" href="#279">279</a>     }<a name="280" href="#280">280</a> <a name="281" href="#281">281</a>     <em>/**<em>*</em></em><a name="282" href="#282">282</a> <em>     * Pass the CrawlURI to all appropriate processors</em><a name="283" href="#283">283</a> <em>     *</em><a name="284" href="#284">284</a> <em>     * @throws InterruptedException</em><a name="285" href="#285">285</a> <em>     */</em><a name="286" href="#286">286</a>     <strong>private</strong> <strong>void</strong> processCrawlUri() throws InterruptedException {<a name="287" href="#287">287</a>         currentCuri.setThreadNumber(<strong>this</strong>.serialNumber);<a name="288" href="#288">288</a>         currentCuri.setNextProcessorChain(controller.getFirstProcessorChain());<a name="289" href="#289">289</a>         lastStartTime = System.currentTimeMillis();<a name="290" href="#290">290</a> <em class="comment">//        System.out.println(currentCuri);</em><a name="291" href="#291">291</a>         <strong>try</strong> {<a name="292" href="#292">292</a>             <strong>while</strong> (currentCuri.nextProcessorChain() != <strong>null</strong>) {<a name="293" href="#293">293</a>                 setStep(STEP_ABOUT_TO_BEGIN_CHAIN);<a name="294" href="#294">294</a>                 <em class="comment">// Starting on a new processor chain.</em><a name="295" href="#295">295</a>                 currentCuri.setNextProcessor(currentCuri.nextProcessorChain().getFirstProcessor());<a name="296" href="#296">296</a>                 currentCuri.setNextProcessorChain(currentCuri.nextProcessorChain().getNextProcessorChain());<a name="297" href="#297">297</a> <a name="298" href="#298">298</a>                 <strong>while</strong> (currentCuri.nextProcessor() != <strong>null</strong>) {<a name="299" href="#299">299</a>                     setStep(STEP_ABOUT_TO_BEGIN_PROCESSOR);<a name="300" href="#300">300</a>                     <a href="../../../../org/archive/crawler/framework/Processor.html">Processor</a> currentProcessor = getProcessor(currentCuri.nextProcessor());<a name="301" href="#301">301</a>                     currentProcessorName = currentProcessor.getName();<a name="302" href="#302">302</a>                     continueCheck();<a name="303" href="#303">303</a> <em class="comment">//                    long memBefore = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024;</em><a name="304" href="#304">304</a>                     currentProcessor.process(currentCuri);<a name="305" href="#305">305</a> <em class="comment">//                    long memAfter = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1024;</em><a name="306" href="#306">306</a> <em class="comment">//                    System.out.println((memAfter-memBefore)+"K in "+currentProcessorName);</em><a name="307" href="#307">307</a>                 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -