网络程序设计lab4Thread和Runnable接口.doc

网络程序设计lab4Thread和Runnable接口.doc

ID:50893897

大小:347.50 KB

页数:14页

时间:2020-03-15

网络程序设计lab4Thread和Runnable接口.doc_第1页
网络程序设计lab4Thread和Runnable接口.doc_第2页
网络程序设计lab4Thread和Runnable接口.doc_第3页
网络程序设计lab4Thread和Runnable接口.doc_第4页
网络程序设计lab4Thread和Runnable接口.doc_第5页
资源描述:

《网络程序设计lab4Thread和Runnable接口.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、2012-2013学年第二学期课程实验报告课程名称:Java网络编程实验名称:姓名班级学号实验台编号同组同学实验课表现出勤、表现得分25%25实验报告得分50%实验总分操作结果得分25%25实验目的1.熟悉线程程序2.熟悉Thread和Runnable接口3.了解线程的竞争条件实验内容(实验步骤和实验结果的简单描述,方便同学自己以后阅读)1.用继承Thread和实现Runnable接口方式各写一个获取多个文件的摘要信息的程序2.写一个采用轮询方式处理线程竞争条件的程序[利用1中的线程序]3.写一个采用静态方法进行回调方式处理线程竞争条件的程序[

2、利用1中的线程序]4.写一个采用实例回调方式处理线程竞争条件的程序[利用1中的线程序]1.提供源代码和运行结果/**Tochangethistemplate,chooseTools

3、Templates*andopenthetemplateintheeditor.*//****@authorAshley*/importjava.io.File;importjava.io.FileInputStream;importjava.io.IOException;importjava.security.DigestInputStream;importjav

4、a.security.MessageDigest;importjava.security.NoSuchAlgorithmException;publicclassDigestThreadextendsThread{privateFileinput;publicDigestThread(Fileinput){this.input=input;}publicvoidrun(){try{FileInputStreamin=newFileInputStream(input);MessageDigestsha=MessageDigest.getInsta

5、nce("SHA");DigestInputStreamdin=newDigestInputStream(in,sha);intb;while((b=din.read())!=-1);din.close();byte[]digest=sha.digest();StringBufferresult=newStringBuffer(input.toString());result.append(":");for(inti=0;i

6、rintln(result);}catch(IOExceptionex){System.err.println(ex);}catch(NoSuchAlgorithmExceptionex){System.err.println(ex);}}publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubfor(inti=0;i

7、}}}/**Tochangethistemplate,chooseTools

8、Templates*andopenthetemplateintheeditor.*//****@authorAshley*/importjava.io.File;importjava.io.FileInputStream;importjava.io.IOException;importjava.security.DigestInputStream;importjava.security.MessageDigest;importjava.security.NoSuchA

9、lgorithmException;publicclassDigestRunnableimplementsRunnable{/***@paramargs*/privateFileinput;publicDigestRunnable(Fileinput){this.input=input;}publicvoidrun(){try{FileInputStreamin=newFileInputStream(input);MessageDigestsha=MessageDigest.getInstance("SHA");DigestInputStrea

10、mdin=newDigestInputStream(in,sha);intb;while((b=din.read())!=-1);din.close(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。