⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.java

📁 用Java写的面相对象的数据库管理系统
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: Client.java,v 1.4 2000/10/28 16:55:20 daniela Exp $package org.ozoneDB.test.deadlocks;import org.ozoneDB.*;import org.ozoneDB.test.*;/** */class AccessThread extends Thread {    RemoteDatabase db;    Garage g1;    Garage g2;            /** */    public AccessThread( RemoteDatabase _db, String _g1, String _g2 ) {        System.out.println( "thread: g1 = " + _g1 );        db = _db;        g1 = (Garage)db.objectForName( _g1 );        g2 = (Garage)db.objectForName( _g2 );    }            /** */    public void run() {        try {            System.out.println( g1.toString() );            g1._langeTA( g2 );            g1.printAll();        } catch (Exception e) {            e.printStackTrace();        }     } }/** */public class Client extends Object {            public static void main( String[] args ) throws Exception {        try {            // 1st connection to remote database            RemoteDatabase db = new RemoteDatabase();            db.open( "localhost", 3333 );            System.out.println( "connected (remote)..." );                        // 2nd connection to remote database            RemoteDatabase db2 = new RemoteDatabase();            db2.open( "localhost", 3333 );            System.out.println( "connected (remote)..." );                        Garage garage1 = (Garage)db.objectForName( "g1" );            Garage garage2 = (Garage)db.objectForName( "g2" );            if (garage1 == null) {                System.out.println( "neue objekte erzeugen" );                garage1 = (Garage)db.createObject( GarageImpl.class.getName(), Database.Private, "g1" );                garage2 = (Garage)db.createObject( GarageImpl.class.getName(), Database.Private, "g2" );            }                         Thread t1 = new AccessThread( db, "g1", "g2" );            t1.setPriority( Thread.currentThread().getPriority() );            t1.setName( "t1" );            t1.start();                        Thread.currentThread().sleep( 2000 );                        Thread t2 = new AccessThread( db2, "g2", "g1" );            t2.setPriority( Thread.currentThread().getPriority() );            t2.setName( "t2" );            t2.start();                        Thread.currentThread().sleep( 1000 );            while (t1.isAlive() || t2.isAlive()) {                Thread.currentThread().sleep( 100 );            }                         db.close();            db2.close();            System.out.println( "deconnected..." );        } catch (Exception e) {            e.printStackTrace();            // signal error            System.exit( 1 );        }     }     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -