基于Java多线程的并行计算技术研究及应用_郭广军

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

:2004-10-11.:(10273016);(03B033).:(1971-),,,,,、. :1000-1190(2005)02-0169-05基于Java多线程的并行计算技术研究及应用郭广军1,2,胡玉平1,戴经国1(1.,417000;2.,430072) :、Java,Java、,,,Java.:Java;;;;;:TP311:A  ,,.,,.,,,,[1].Java,,.Java、,,.11.1Java,.Java,Thread,、、、、、,.CPUCPU,,.Java,,5[1,3],1.1 ①(Newborn):new,Newborn.,,,.start().Java.Thread:Java.lang.Thread,Thread.Runnable:Runnablerun(),,Runnable.392()Vol.39No.220056JOURNALOFCENTRALCHINANORMALUNIVERSITY(Nat.Sci.)Jun.2005②(Runnable):start(),,.CPU,CPU.,.③(Running):CPU,run(),,.Run-ning,.④(Blocked):,join()、wait()、sleep()sus-pend()I/O,CPU,.,notify()、noti-fyAll()resume()I/O,.⑤(Dead):,stop()destroy(),,.1.2.,,,,,,,.()Java[4].,,.Java,,“synchronized”,,,:[public|private]synchronized[type](){},this;:[public|private]synchronized(){},,synchronized(),.,.Java,01,1.,.synchronized,.,synchronized(monitor),monitor1;1,monitor0,,monitor1;0,monitor,monitor1,monitor.,synchronized,.,,,“”,,,,.,.,.1.3CPU,CPU,、.Java,.Java1~10,,,5.,setPriority().Java[1].,CPU.,,,.“”,Java,sleep()、join()、wait()、notify()notifyAll(),.,sleep(),join(),wait()170 ()39,wait,,notify()notifyAll().notify()noti-fyAll(),wait,.(daemon),,run().,setDaemon(true).,,./,,,.1.4,、,[3].,..,,.①:,;②:AB,C,CA;③:.AB,,A,B;④:,,.,,:,;,;;,,,;.wait(),.wait()/no-tify(),.Java,.,,notify().notify(),,notify().notify().1.5(Pipe),.JavaPipedInputStreamPipedOutputStream.PipedInputStream,;Piped-OutputStream,,.,PipedOutStream,PipedInputStream.,.,,.2,,,.,,.Java“”,:[5].B/S.,examServermain(),examServer,accept,socketexamServerThread,.importjava.io.*;importjava.net.*;importjava.util.*;publicclassexamServer//(){finalintSPORT=6868;//publicexamServer()//examServer {ServerSocketserver=null;//examServer Socketbrowser=null;// while(true)  {try{server=newServerSocket(SPORT);//ServerSocket   System.out.println(Welcometologintheexam-Server!);   System.out.println(TheexamServerisready!);171 2:Java   System.out.println(PortofexamServer:+SPORT);  }  catch(IOExceptione1){System.out.println(......);}  try{browser=server.accept();   //()   InetAddressaddress=browser.getInetAddress();   System.out.println(IP:+address);}  catch(IOExceptione){}  if(browser!=null)//   {newexamServerThread(browser).start();}  else{continue;}  } } publicstaticvoidmain(Stringargs[]){ newexamServer();}}//classexamServerThreadextendsThread{inti=0;Socketsocket=null;//Filefile=null;DataOutputStreamout=null;//DataInputStreamin=null;//ReadTestquestionreadtestquestion=null;//Read-Testquestionbooleanavisoexaminterfacetime=true;publicexamServerThread(Sockett)//{socket=t;//examServer //、 try{in=newDataInputStream(socket.getInputStream());  out=newDataOutputStream(socket.getOutput-Stream());} catch(IOExceptione){} readtestquestion=newReadTestquestion();//}publicvoidrun(){while(true) {Strings=null;  try{s=in.readUTF();  if(s.startsWith())   {Stringcurrentdirectory=System.getProperty(examinee.dir);   Filedir=newFile(currentdirectory);   FileNamefileTxt=newFileName(txt);   StringfileName[]=dir.list(fileTxt);   for(inti=0;ifileName.length;i++)   {out.writeUTF(:+fileName[i]);}   out.writeUTF(:);   }   elseif(s.startsWith(:))   {StringfileName=s.substring(s.indexOf(:)+1);   readtestquestion.setFilename(fileName);   readtestquestion.setcompleteexam(false);   avisoexaminterfacetime=true;   }   elseif(s.startsWith())   {StringcontentTest=readtestquestion.getTest-Content();   out.writeUTF(:+contentTest);   if(avisoexaminterfacetime==true)   {longtime=readtestquestion.getTime();   out.writeUTF(:+time);   avisoexaminterfacetime=false;}   if(readtestquestion.getcompleteexam())   {out.writeUTF(:);}  }  elseif(s.startsWith(:))  {Stringanswer=s.substring(s.indexOf(:)+1);  readtestquestion.setSelection(answer);}  elseif(s.startsWith())  {intscore=readtestquestion.getScore();  Stringmessages=readtestquestion.getMessages();  out.writeUTF(:+score+\n+messages);}  }  catch(IOExceptionee){  try{socket.close();}  catch(Exceptioneee){}  System.out.println(!!!);  break;}}}}//,.,,,,、,.,、.,,,.172 ()393Java、、、、、,.Java,,,.,..:;CPU;;、.Java,,.Java.:[1] ,.——Java[M].:,2003.259~264.[2] ,.Java[J].,2004,14(3):34~35.[3] BruceEckel.ThinkinginJava,3rd.[M].:,2002.661~680.[4] LewisB,BergDJ.:Java[M].:,2000.[5] FunC,LiJB,WonKP.DevelopmentofaJava-baseddis-tributedplatformfortheimplementationofcomputationin-telligencetechniques[A].IEEE:Proceedingsof2004Inter-nationalConferenceonMachineLearningandCybernetics[C].Washington:IEEEPress,2004.4156~4161.Researchandapplicationofmultithread-basedparallelcomputinginJavaGUOGuang-jun1,2,HUYu-ping1,DAIJing-guo1(1.DepartmentofComputerScience,HunanUniversityofHumanitiesandScienceandTechnology,Loudi,Hunan417000;2.InternationalSchoolofSoftware,WuhanUniversity,Wuhan430072)Abstract:AsforthedesigningofhighrealiableandqualitativeJavaparallelprogram,theprincipleofsynchronizationmechanism、schedulingalgorithmandcommunicationmechanismmultithread-basedinJavaareanalyzedatfirst,thenthemethodofmulti-thread-basedParallelcomputingprogrammingisprobedinto,andanapplicationin-stanceofmultithread-basedconcurrentcomputationispresented,atlast,thedeficiencyofmultithreadin

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功