1.轮询 // 执行线程 for (Thread t : threadlist) { t.start(); } rewhile:while (true) { try { Thread.sleep(1L); } catch (InterruptedException e) { e.printStackTrace(); } for (Thread t : threadlist) { if (t.isAlive()) continue rewhile; } threadlist.clear(); threadlist = null; return; }2.连接线程 ListjoinReturnDigestList = new ArrayList ( fileList.size()); for (File file : fileList) { JoinReturnDigest joinReturnDigest = new JoinReturnDigest(file); joinReturnDigestList.add(joinReturnDigest); joinReturnDigest.start(); } StringBuffer result_buffer = new StringBuffer(); for(JoinReturnDigest joinReturnDigest : joinReturnDigestList){ try { //连接线程 join 等待该线程终止 joinReturnDigest.join(); result_buffer.append(joinReturnDigest.getDigest()); } catch (InterruptedException e) { e.printStackTrace(); } }3.回调Class Thread: @Override public void run() { FileInputStream fileInputStream; try { fileInputStream = new FileInputStream(file); MessageDigest messageDigest = MessageDigest.getInstance("SHA"); DigestInputStream digestInputStream = new DigestInputStream(fileInputStream, messageDigest); while(digestInputStream.read() != -1){} byte[] bytes = messageDigest.digest(); this.sendDigest(bytes); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } Class CallBack: public void calculateDigest() { ListCallbackDigest listCallbackDigest = new ListCallbackDigest(file); listCallbackDigest.addDigestListener(this); Thread thread = new Thread(listCallbackDigest); thread.start(); } @Override public void digestCalculated(byte[] digest) { this.digest = digest; System.out.println(this); }