01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-2001 by SMB GmbH. All rights reserved.
06: //
07: // $Id: Client.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
08:
09: package org.ozoneDB.test.deadlocks;
10:
11: import org.ozoneDB.*;
12: import org.ozoneDB.test.simple.*;
13:
14: /**
15: */
16: class AccessThread extends Thread {
17: RemoteDatabase db;
18: Garage g1;
19: Garage g2;
20:
21: /** */
22: public AccessThread(RemoteDatabase _db, String _g1, String _g2)
23: throws Exception {
24: System.out.println("thread: g1 = " + _g1);
25: db = _db;
26: g1 = (Garage) db.objectForName(_g1);
27: g2 = (Garage) db.objectForName(_g2);
28: }
29:
30: /** */
31: public void run() {
32: try {
33: System.out.println(g1.toString());
34: g1._langeTA(g2);
35: g1.printAll();
36: } catch (Exception e) {
37: e.printStackTrace();
38: }
39: }
40: }
41:
42: /**
43: */
44: public class Client extends Object {
45:
46: public static void main(String[] args) throws Exception {
47: try {
48: // 1st connection to remote database
49: RemoteDatabase db = new RemoteDatabase();
50: db.open("localhost", 3333);
51: System.out.println("connected (remote)...");
52:
53: // 2nd connection to remote database
54: RemoteDatabase db2 = new RemoteDatabase();
55: db2.open("localhost", 3333);
56: System.out.println("connected (remote)...");
57:
58: Garage garage1 = (Garage) db.objectForName("g1");
59: Garage garage2 = (Garage) db.objectForName("g2");
60: if (garage1 == null) {
61: System.out.println("neue objekte erzeugen");
62: garage1 = (Garage) db.createObject(GarageImpl.class
63: .getName(), Database.Private, "g1");
64: garage2 = (Garage) db.createObject(GarageImpl.class
65: .getName(), Database.Private, "g2");
66: }
67:
68: Thread t1 = new AccessThread(db, "g1", "g2");
69: t1.setPriority(Thread.currentThread().getPriority());
70: t1.setName("t1");
71: t1.start();
72:
73: Thread.currentThread().sleep(2000);
74:
75: Thread t2 = new AccessThread(db2, "g2", "g1");
76: t2.setPriority(Thread.currentThread().getPriority());
77: t2.setName("t2");
78: t2.start();
79:
80: Thread.currentThread().sleep(1000);
81: while (t1.isAlive() || t2.isAlive()) {
82: Thread.currentThread().sleep(100);
83: }
84:
85: db.close();
86: db2.close();
87: System.out.println("deconnected...");
88: } catch (Exception e) {
89: e.printStackTrace();
90: // signal error
91: System.exit(1);
92: }
93: }
94:
95: }
|