Java多线程结构.rar

  • Again123a
    了解作者
  • Java
    开发工具
  • 12KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-02-16 00:35
    上传日期
Java中的多线程结构请大家观看不足的地方请指教,大家可以一语既出的观看和指导。
Java多线程结构.rar
  • Java多线程结构
  • Java中的多线程结构.docx
    15KB
内容介绍
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <meta name="generator" content="pdf2htmlEX"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css"> <link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css"> <link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/626915314f8811599e1c16ff/raw.css"> <script src="https://static.pudn.com/base/js/compatibility.min.js"></script> <script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script> <script> try{ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({}); }catch(e){} </script> <title></title> </head> <body> <div id="sidebar" style="display: none"> <div id="outline"> </div> </div> <div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/626915314f8811599e1c16ff/bg1.jpg"><div class="c x0 y1 w2 h2"><div class="t m0 x1 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">&#23454;&#20363;</div><div class="t m0 x1 h4 y3 ff2 fs0 fc0 sc0 ls0 ws0">class R<span class="_ _0"></span>unnableDemo implements R<span class="_ _0"></span>unnable {</div><div class="t m0 x1 h4 y4 ff2 fs0 fc0 sc0 ls0 ws0"> private Thread t;</div><div class="t m0 x1 h4 y5 ff2 fs0 fc0 sc0 ls0 ws0"> private String threadName;</div><div class="t m0 x1 h4 y6 ff2 fs0 fc0 sc0 ls0 ws0"> </div><div class="t m0 x1 h4 y7 ff2 fs0 fc0 sc0 ls0 ws0"> R<span class="_ _0"></span>unnableDemo( String name) {</div><div class="t m0 x1 h4 y8 ff2 fs0 fc0 sc0 ls0 ws0"> threadName = name;</div><div class="t m0 x1 h4 y9 ff2 fs0 fc0 sc0 ls0 ws0"> System.out.println("Creating " + thr<span class="_ _0"></span>eadName );</div><div class="t m0 x1 h4 ya ff2 fs0 fc0 sc0 ls0 ws0"> }</div><div class="t m0 x1 h4 yb ff2 fs0 fc0 sc0 ls0 ws0"> </div><div class="t m0 x1 h4 yc ff2 fs0 fc0 sc0 ls0 ws0"> public void run() {</div><div class="t m0 x1 h4 yd ff2 fs0 fc0 sc0 ls0 ws0"> System.out.println("R<span class="_ _0"></span>unning " + threadName );</div><div class="t m0 x1 h4 ye ff2 fs0 fc0 sc0 ls0 ws0"> try {</div><div class="t m0 x1 h4 yf ff2 fs0 fc0 sc0 ls0 ws0"> for(int i = 4; i &gt; 0; i--) <span class="_ _1"></span>{</div><div class="t m0 x1 h4 y10 ff2 fs0 fc0 sc0 ls0 ws0"> System.out.println("Thread: " + thr<span class="_ _0"></span>eadName<span class="_ _1"></span> + ", " + i);</div><div class="t m0 x1 h3 y11 ff2 fs0 fc0 sc0 ls0 ws0"> // <span class="_ _1"></span><span class="ff1">&#35753;&#32447;&#31243;&#30561;&#30496;&#19968;&#20250;</span></div><div class="t m0 x1 h4 y12 ff2 fs0 fc0 sc0 ls0 ws0"> Thread.sleep(50);</div><div class="t m0 x1 h4 y13 ff2 fs0 fc0 sc0 ls0 ws0"> }</div><div class="t m0 x1 h4 y14 ff2 fs0 fc0 sc0 ls0 ws0"> }catch (InterruptedEx<span class="_ _0"></span>ception e) {</div><div class="t m0 x1 h4 y15 ff2 fs0 fc0 sc0 ls0 ws0"> System.out.println("Thread " + thr<span class="_ _0"></span>eadName + " in<span class="_ _1"></span>ter<span class="_ _0"></span>rupted<span class="_ _1"></span>.");</div><div class="t m0 x1 h4 y16 ff2 fs0 fc0 sc0 ls0 ws0"> }</div><div class="t m0 x1 h4 y17 ff2 fs0 fc0 sc0 ls0 ws0"> System.out.println("Thread " + thr<span class="_ _0"></span>eadName + " exiting.");</div><div class="t m0 x1 h4 y18 ff2 fs0 fc0 sc0 ls0 ws0"> }</div><div class="t m0 x1 h4 y19 ff2 fs0 fc0 sc0 ls0 ws0"> </div><div class="t m0 x1 h4 y1a ff2 fs0 fc0 sc0 ls0 ws0"> public void start () {</div><div class="t m0 x1 h4 y1b ff2 fs0 fc0 sc0 ls0 ws0"> System.out.println("Starting " + threadName );</div><div class="t m0 x1 h4 y1c ff2 fs0 fc0 sc0 ls0 ws0"> if (t == null) {</div><div class="t m0 x1 h4 y1d ff2 fs0 fc0 sc0 ls0 ws0"> t = new Thread (this, thr<span class="_ _0"></span>eadName);</div><div class="t m0 x1 h4 y1e ff2 fs0 fc0 sc0 ls0 ws0"> t.start ();</div><div class="t m0 x1 h4 y1f ff2 fs0 fc0 sc0 ls0 ws0"> }</div><div class="t m0 x1 h4 y20 ff2 fs0 fc0 sc0 ls0 ws0"> }</div><div class="t m0 x1 h4 y21 ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x1 h4 y22 ff2 fs0 fc0 sc0 ls0 ws0"> </div><div class="t m0 x1 h4 y23 ff2 fs0 fc0 sc0 ls0 ws0">public class T<span class="_ _2"></span>estThread {</div><div class="t m0 x1 h4 y24 ff2 fs0 fc0 sc0 ls0 ws0"> </div><div class="t m0 x1 h4 y25 ff2 fs0 fc0 sc0 ls0 ws0"> public static void main(String args[]) {</div><div class="t m0 x1 h4 y26 ff2 fs0 fc0 sc0 ls0 ws0"> R<span class="_ _0"></span>unnableDemo R1 = new R<span class="_ _0"></span>unnableDemo( "Thread-1");</div><div class="t m0 x1 h4 y27 ff2 fs0 fc0 sc0 ls0 ws0"> R1.start();</div><div class="t m0 x1 h4 y28 ff2 fs0 fc0 sc0 ls0 ws0"> </div><div class="t m0 x1 h4 y29 ff2 fs0 fc0 sc0 ls0 ws0"> R<span class="_ _0"></span>unnableDemo R2 = new R<span class="_ _0"></span>unnableDemo( "Thread-2");</div><div class="t m0 x1 h4 y2a ff2 fs0 fc0 sc0 ls0 ws0"> R2.start();</div><div class="t m0 x1 h4 y2b ff2 fs0 fc0 sc0 ls0 ws0"> } </div><div class="t m0 x1 h4 y2c ff2 fs0 fc0 sc0 ls0 ws0">}</div></div></div><div class="pi" data-data='{"ctm":[1.611850,0.000000,0.000000,1.611850,0.000000,0.000000]}'></div></div> </body> </html>
评论
    相关推荐