1 import jcifs.util.transport.TransportException; 2 import jcifs.smb.*; 3 4 public class InterruptTest extends Thread { 5 6 String url; 7 8 public InterruptTest(String url) { 9 this.url = url; 10 } 11 public void run() { 12 for (int i = 0; i < 10; i++) { 13 try { 14 SmbFileInputStream in = new SmbFileInputStream(url); 15 16 byte[] b = new byte[10]; 17 while(in.read( b ) > 0) { 18 ; 19 } 20 21 in.close(); 22 } catch(SmbException se) { 23 Throwable t = se.getRootCause(); 24 if (t instanceof TransportException) { 25 TransportException te = (TransportException)t; 26 t = te.getRootCause(); 27 if (t instanceof InterruptedException ) { 28 System.out.println("interrupted ok"); 29 continue; 30 } 31 } 32 se.printStackTrace(); 33 try { Thread.sleep(500); } catch(InterruptedException ie) {} 34 } catch(Exception e) { 35 e.printStackTrace(); 36 break; 37 } 38 } 39 } 40 41 public static void main( String argv[] ) throws Exception { 42 InterruptTest it = new InterruptTest(argv[0]); 43 it.start(); 44 for (int i = 0; i < 10; i++) { 45 Thread.sleep(200); 46 it.interrupt(); 47 } 48 } 49 } 50 51 | Popular Tags |