KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > InterruptTest


1 import jcifs.util.transport.TransportException;
2 import jcifs.smb.*;
3
4 public class InterruptTest extends Thread JavaDoc {
5
6     String JavaDoc url;
7
8     public InterruptTest(String JavaDoc 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 JavaDoc t = se.getRootCause();
24                 if (t instanceof TransportException) {
25                     TransportException te = (TransportException)t;
26                     t = te.getRootCause();
27                     if (t instanceof InterruptedException JavaDoc) {
28                         System.out.println("interrupted ok");
29                         continue;
30                     }
31                 }
32                 se.printStackTrace();
33                 try { Thread.sleep(500); } catch(InterruptedException JavaDoc ie) {}
34             } catch(Exception JavaDoc e) {
35                 e.printStackTrace();
36                 break;
37             }
38         }
39     }
40
41     public static void main( String JavaDoc argv[] ) throws Exception JavaDoc {
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