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

📄 lockmanagertest.java

📁 分布式数据库原形代码 可以支持个用户同时登陆到数据库中查询需要的资源
💻 JAVA
字号:
package lockmgr;import java.util.*;class LockManagerTest {        static LockManager lm = new LockManager();    public static void main (String[] args) {	test1();	//test2();    }    static void test1()    {	System.out.println("Deadlock test");	Transaction t1 = new Transaction(1, "rl a sl 3000 wl b ua");	Transaction t2 = new Transaction(2, "rl b sl 10 wl a ua");	t1.start();	t2.start();    }    static void test2()    {	System.out.println("Lock conversion test");	Transaction t1 = new Transaction(1, "rl a sl 10 wl a ua");	Transaction t2 = new Transaction(2, "rl a sl 2000 ua"); 	t1.start();	t2.start();    }	    static class Transaction extends Thread {		int xid;	StringTokenizer st;		public Transaction(int xid, String ops) 	{	    this.xid = xid;	    st = new StringTokenizer(ops);	}		public void run()	{	    try {		while (st.hasMoreTokens()) {		    String opcode = st.nextToken();		    if (opcode.equalsIgnoreCase("rl")) {			String param = st.nextToken();			lm.lock(xid, param, LockManager.READ);			System.out.println("Transaction " + xid +					   " got rl(" + param + ")");		    }		    else if (opcode.equalsIgnoreCase("wl")) {			String param = st.nextToken();			lm.lock(xid, param, LockManager.WRITE);			System.out.println("Transaction " + xid +					   " got wl(" + param + ")");		    }		    else if (opcode.equalsIgnoreCase("ua")) {			lm.unlockAll(xid);		    }		    else if (opcode.equalsIgnoreCase("sl")) {			String param = st.nextToken();			int sleepTime = Integer.parseInt(param);			try {			    this.sleep(sleepTime);			}			catch (InterruptedException ie) {			}		    }		    else {			System.out.println("Unknown opcode " + opcode);			break;		    }		}	    }	    catch (DeadlockException de) {		System.out.println("Transaction " + xid + ": Deadlock...");	    }	    finally {		lm.unlockAll(xid);	    }	}    }}

⌨️ 快捷键说明

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