1 9 package test.deadlocks; 10 11 import org.ozoneDB.Database; 12 import org.ozoneDB.RemoteDatabase; 13 import org.ozoneDB.ExternalDatabase; 14 import test.simple.Garage; 15 import test.simple.GarageImpl; 16 import test.OzoneTestCase; 17 18 19 21 class AccessThread extends Thread { 22 RemoteDatabase db; 23 Garage g1; 24 Garage g2; 25 26 27 28 public AccessThread(RemoteDatabase _db, String _g1, String _g2) throws Exception { 29 System.out.println("thread: g1 = " + _g1); 30 db = _db; 31 g1 = (Garage) db.objectForName(_g1); 32 g2 = (Garage) db.objectForName(_g2); 33 } 34 35 36 37 public void run() { 38 try { 39 System.out.println(g1.toString()); 40 g1._langeTA(g2); 41 g1.printAll(); 42 } catch (Exception e) { 43 e.printStackTrace(); 44 } 45 } 46 } 47 48 49 51 public class DeadlockTest extends OzoneTestCase { 52 53 public DeadlockTest(String name) { 54 super(name); 55 } 56 57 58 public void testDeadlock() { 59 try { 60 if (db() instanceof RemoteDatabase) { 62 63 } else { 64 System.out.println("testDeadlock only works on remote databases"); 65 return; 66 } 67 RemoteDatabase db = (RemoteDatabase) db(); 68 69 RemoteDatabase db2 = (RemoteDatabase) ExternalDatabase.openDatabase(getDbUrl()); 71 System.out.println("connected (remote)..."); 72 73 Garage garage1 = (Garage) db.objectForName("g1"); 74 Garage garage2 = (Garage) db.objectForName("g2"); 75 if (garage1 == null) { 76 System.out.println("neue objekte erzeugen"); 77 garage1 = (Garage) db.createObject(GarageImpl.class.getName(), Database.Private, "g1"); 78 garage2 = (Garage) db.createObject(GarageImpl.class.getName(), Database.Private, "g2"); 79 } 80 81 Thread t1 = new AccessThread(db, "g1", "g2"); 82 t1.setPriority(Thread.currentThread().getPriority()); 83 t1.setName("t1"); 84 t1.start(); 85 86 Thread.currentThread().sleep(2000); 87 88 Thread t2 = new AccessThread(db2, "g2", "g1"); 89 t2.setPriority(Thread.currentThread().getPriority()); 90 t2.setName("t2"); 91 t2.start(); 92 93 Thread.currentThread().sleep(1000); 94 while (t1.isAlive() || t2.isAlive()) { 95 Thread.currentThread().sleep(100); 96 } 97 db2.close(); 98 System.out.println("deconnected..."); 99 } catch (Exception e) { 100 fail(e.toString()); 101 } 102 } 103 } 104 | Popular Tags |