1 package demo.mtclient; 2 3 class ClientThread 4 extends Thread 5 implements ObserverOperations 6 { 7 private MyServer srv; 8 private String msg; 9 private int id; 10 private int time; 11 12 private Observer me; 13 14 public ClientThread ( MyServer _s, String _x, int _id) 15 { 16 srv = _s; 17 msg = _x; 18 id = _id; 19 time = 1; 20 setDaemon(true); 21 } 22 23 public void setMe(Observer obs) 24 { 25 me = obs; 26 } 27 28 public void run() 29 { 30 System.out.println("ClientThread " + id + " starts"); 31 int lifeTime = 10; 32 try 33 { 34 while( lifeTime > 0 ) 35 { 36 lifeTime--; 37 String a[] = srv.arryfy( msg,5 ); 38 System.out.println( id + ", " + lifeTime + 39 " to go." + srv.writeMessages( a, me )); 40 sleep(500); 41 } 42 } 43 catch( org.omg.CORBA.COMM_FAILURE cf ) 44 { 45 System.out.println("Communication failure"); 46 } 47 catch (Exception e) 48 { 49 e.printStackTrace(); 50 } 51 System.out.println("thread exits..."); 52 } 53 54 public void update1( Observer o) 55 { 56 System.out.println("Client " + id + " update1"); 57 o.update2(); 58 } 59 60 public void update2() 61 { 62 System.out.println("Client " + id + " update2"); 63 } 64 } 65 66 67 | Popular Tags |