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

📄 multipleaccesstest.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-2001 by SMB GmbH. All rights reserved.
//
// $Id$

package test.multiple_access;

import org.ozoneDB.Database;
import org.ozoneDB.ExternalDatabase;
import test.simple.Garage;
import test.simple.GarageImpl;
import test.OzoneTestCase;


class AccessThread extends Thread {
    ExternalDatabase db;


    public AccessThread(ExternalDatabase _db) {
        db = _db;
    }


    public void run() {
        try {
            Garage garage = (Garage) db.objectForName("MG");
            System.out.println("thread(" + hashCode() + "): connected...");
            garage._populate(new Integer(10));
            garage.printAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


public class MultipleAccessTest extends OzoneTestCase {


    public MultipleAccessTest(String name) {
        super(name);
    }

    public void testMultipleAccess() {
        try {
            // todo: not sure if this is supposed to work for localDatabase
            ExternalDatabase db = db();

            //            LocalDatabase db = new LocalDatabase();
            //            db.open ("/tmp/db", LogWriter.DEBUG3);

            db.reloadClasses();

            ExternalDatabase db2 = ExternalDatabase.openDatabase(getDbUrl());
            //            db2.open ("localhost", 3333);

            Garage garage = (Garage) db.objectForName("MG");
            if (garage == null) {
                garage = (Garage) db.createObject(GarageImpl.class.getName(), Database.Public, "MG");
            }

            Thread t1 = new AccessThread(db);
            t1.setPriority(Thread.currentThread().getPriority());
            t1.setName("t1");
            t1.start();

            System.out.println("wait...");
            Thread.sleep(3000);
            System.out.println("go on...");

            Thread t2 = new AccessThread(db);
            t2.setPriority(Thread.currentThread().getPriority());
            t2.setName("t2");
            t2.start();

            Thread.sleep(1000);
            while (t1.isAlive() || t2.isAlive()) {
                System.out.println("wait for threads...");
                Thread.sleep(1000);
            }

            // db.deleteObject (garage);

            db2.close();
            System.out.println("deconnected...");
        } catch (Throwable e) {
            fail(e.toString());
        }
    }
}

⌨️ 快捷键说明

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