1 25 26 package org.objectweb.jonas.stests.manac; 27 28 import java.rmi.RemoteException ; 29 import javax.ejb.RemoveException ; 30 import javax.naming.Context ; 31 import javax.rmi.PortableRemoteObject ; 32 33 34 38 public class A_remthread extends Thread { 39 String managerName; 40 String name; 41 int accounts; 42 int loops; 43 Context ictx; 44 45 public A_remthread(String mName, int num, Context ictx, int accounts, int loops) { 46 managerName = mName; 47 name = managerName + "_remac_" + num; 48 setName(name); 49 this.ictx = ictx; 50 this.accounts = accounts; 51 this.loops = loops; 52 } 53 54 57 private int random(int max) throws RemoteException { 58 double d = Math.random(); 59 int ret = (int) (max * d); 60 return ret; 61 } 62 63 public void run() { 64 65 ManagerHome mgrHome = null; 67 Manager mgr = null; 68 try { 69 mgrHome = (ManagerHome) PortableRemoteObject.narrow(ictx.lookup(managerName), 70 ManagerHome.class); 71 mgr = mgrHome.create(F_remove.initialValue); 72 } catch (Exception e) { 73 System.out.println("Cannot Create Session:" + e); 74 return; 75 } 76 77 try { 78 boolean ok = true; 80 for (int i = 0; i < loops; i++) { 81 int a1 = random(accounts); 83 int value = random(100); 85 if (value < 10) { 86 mgr.delAccount(a1); 87 } else { 88 mgr.getAccount(a1); 89 } 90 } 91 92 mgr.remove(); 94 } catch (RemoteException e) { 95 System.out.println("Thread " + name + " : " + e); 96 F_remove.threadfail = true; 97 } catch (RemoveException e) { 98 System.out.println("Thread " + name + " Cannot remove bean: " + e); 99 F_remove.threadfail = true; 100 } 101 } 102 } 103 | Popular Tags |