1 9 package test.multiple_access; 10 11 import org.ozoneDB.Database; 12 import org.ozoneDB.ExternalDatabase; 13 import test.simple.Garage; 14 import test.simple.GarageImpl; 15 import test.OzoneTestCase; 16 17 18 class AccessThread extends Thread { 19 ExternalDatabase db; 20 21 22 public AccessThread(ExternalDatabase _db) { 23 db = _db; 24 } 25 26 27 public void run() { 28 try { 29 Garage garage = (Garage) db.objectForName("MG"); 30 System.out.println("thread(" + hashCode() + "): connected..."); 31 garage._populate(new Integer (10)); 32 garage.printAll(); 33 } catch (Exception e) { 34 e.printStackTrace(); 35 } 36 } 37 } 38 39 40 public class MultipleAccessTest extends OzoneTestCase { 41 42 43 public MultipleAccessTest(String name) { 44 super(name); 45 } 46 47 public void testMultipleAccess() { 48 try { 49 ExternalDatabase db = db(); 51 52 55 db.reloadClasses(); 56 57 ExternalDatabase db2 = ExternalDatabase.openDatabase(getDbUrl()); 58 60 Garage garage = (Garage) db.objectForName("MG"); 61 if (garage == null) { 62 garage = (Garage) db.createObject(GarageImpl.class.getName(), Database.Public, "MG"); 63 } 64 65 Thread t1 = new AccessThread(db); 66 t1.setPriority(Thread.currentThread().getPriority()); 67 t1.setName("t1"); 68 t1.start(); 69 70 System.out.println("wait..."); 71 Thread.sleep(3000); 72 System.out.println("go on..."); 73 74 Thread t2 = new AccessThread(db); 75 t2.setPriority(Thread.currentThread().getPriority()); 76 t2.setName("t2"); 77 t2.start(); 78 79 Thread.sleep(1000); 80 while (t1.isAlive() || t2.isAlive()) { 81 System.out.println("wait for threads..."); 82 Thread.sleep(1000); 83 } 84 85 87 db2.close(); 88 System.out.println("deconnected..."); 89 } catch (Throwable e) { 90 fail(e.toString()); 91 } 92 } 93 } 94 | Popular Tags |