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.multiple_access;
10:
11: import org.ozoneDB.*;
12: import org.ozoneDB.core.*;
13: import org.ozoneDB.test.simple.*;
14:
15: class AccessThread extends Thread {
16: ExternalDatabase db;
17:
18: public AccessThread(ExternalDatabase _db) {
19: db = _db;
20: }
21:
22: public void run() {
23: try {
24: Garage garage = (Garage) db.objectForName("MG");
25: System.out.println("thread(" + hashCode()
26: + "): connected...");
27: garage._populate(new Integer(10));
28: garage.printAll();
29: } catch (Exception e) {
30: e.printStackTrace();
31: }
32: }
33: }
34:
35: public class Client extends Object {
36:
37: public static void main(String[] args) throws Exception {
38: try {
39: RemoteDatabase db = new RemoteDatabase();
40: db.open("localhost", 3333);
41:
42: // LocalDatabase db = new LocalDatabase();
43: // db.open ("/tmp/db", LogWriter.DEBUG3);
44:
45: db.reloadClasses();
46:
47: RemoteDatabase db2 = new RemoteDatabase();
48: // db2.open ("localhost", 3333);
49:
50: Garage garage = (Garage) db.objectForName("MG");
51: if (garage == null) {
52: garage = (Garage) db.createObject(GarageImpl.class
53: .getName(), Database.Public, "MG");
54: }
55:
56: Thread t1 = new AccessThread(db);
57: t1.setPriority(Thread.currentThread().getPriority());
58: t1.setName("t1");
59: t1.start();
60:
61: System.out.println("wait...");
62: Thread.sleep(3000);
63: System.out.println("go on...");
64:
65: Thread t2 = new AccessThread(db);
66: t2.setPriority(Thread.currentThread().getPriority());
67: t2.setName("t2");
68: t2.start();
69:
70: Thread.sleep(1000);
71: while (t1.isAlive() || t2.isAlive()) {
72: System.out.println("wait for threads...");
73: Thread.sleep(1000);
74: }
75:
76: // db.deleteObject (garage);
77:
78: db.close();
79: db2.close();
80: System.out.println("deconnected...");
81: } catch (Throwable e) {
82: e.printStackTrace(System.out);
83: System.exit(1);
84: }
85: }
86: }
|