1 import java.net.UnknownHostException ; 2 import jcifs.*; 3 4 public class ThreadedUniQuery { 5 6 static class QThread extends Thread { 7 String name; 8 9 QThread( String name ) { 10 super( name + "-thread" ); 11 this.name = name; 12 } 13 14 public void run() { 15 try { 16 System.out.println( getName() + ": started" ); 17 for( int i = 0; i < 15; i++ ) { 18 Thread.sleep( (long)(Math.random() * 1000L )); 19 try { 20 UniAddress.getByName( name, true ); 21 } catch( UnknownHostException uhe ) { 22 uhe.printStackTrace(); 23 } 24 } 25 System.out.println( getName() + ": done" ); 26 } catch( Exception x ) { 27 x.printStackTrace(); 28 } 29 } 30 } 31 32 public static void main(String [] argv) throws Exception { 33 if( argv.length < 2 ) { 34 System.out.println( "java ThreadedUniQuery name [name [name [...]]]" ); 35 return; 36 } 37 38 QThread[] t = new QThread[argv.length]; 39 for( int i = 0; i < argv.length; i++ ) { 40 t[i] = new QThread( argv[i] ); 41 } 42 for( int j = 0; j < argv.length; j++ ) { 43 t[j].start(); 44 } 45 for( int j = 0; j < argv.length; j++ ) { 46 t[j].join(); 47 } 48 Runtime.getRuntime().exit(0); 49 } 50 } 51 | Popular Tags |