📄 deadlocktest.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.deadlocks;import org.ozoneDB.Database;import org.ozoneDB.RemoteDatabase;import org.ozoneDB.ExternalDatabase;import test.simple.Garage;import test.simple.GarageImpl;import test.OzoneTestCase;/** */class AccessThread extends Thread { RemoteDatabase db; Garage g1; Garage g2; /** */ public AccessThread(RemoteDatabase _db, String _g1, String _g2) throws Exception { 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 DeadlockTest extends OzoneTestCase { public DeadlockTest(String name) { super(name); } public void testDeadlock() { try { // 1st connection to remote database if (db() instanceof RemoteDatabase) { } else { System.out.println("testDeadlock only works on remote databases"); return; } RemoteDatabase db = (RemoteDatabase) db(); // 2nd connection to remote database RemoteDatabase db2 = (RemoteDatabase) ExternalDatabase.openDatabase(getDbUrl()); 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); } db2.close(); System.out.println("deconnected..."); } catch (Exception e) { fail(e.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -