📄 metrictests.java
字号:
package poolman.tests;import java.util.*;import java.sql.*;import javax.naming.*;import javax.transaction.*;import java.rmi.RemoteException;import java.rmi.RMISecurityManager;import com.codestudio.sql.*;public class MetricTests { int cycles = 10; int checkOuts = 6; long waitTime = 5000; public static void main(String args[]) { System.setSecurityManager(new RMISecurityManager()); MetricTests t = new MetricTests(); } public MetricTests() { setUp(); //testLifeguard(); testConnectionsOverTime(); } public void setUp() { try { Connection c = getConnection(); synchronized(this) { wait(waitTime); } c.close(); } catch (Exception se) {} /* try { this.ctx = getContext(); if (ctx != null) System.out.println("got naming context"); } catch (NamingException ne) { ne.printStackTrace(); } */ } public void testLifeguard() { try { for (int n=0; n<cycles; n++) { ArrayList checkedOut = new ArrayList(); for (int i=0; i<checkOuts; i++) { checkedOut.add(getConnection()); } synchronized(this) { wait(waitTime); } } } catch (Exception e) { e.printStackTrace(); } } public void testConnectionsOverTime() { try { for (int n=0; n<cycles; n++) { ArrayList checkedOut = new ArrayList(); for (int i=0; i<checkOuts; i++) { System.out.println("OPEN================"); long started = System.currentTimeMillis(); checkedOut.add(getConnection()); System.out.println("Elapsed: " + (System.currentTimeMillis() - started)); } synchronized(this) { System.out.println("WAITING..."); wait(waitTime); } for (int i=0; i<checkOuts; i++) { Connection con = (Connection) checkedOut.get(i); try { System.out.println("CLOSE================"); long started = System.currentTimeMillis(); con.close(); System.out.println("Elapsed: " + (System.currentTimeMillis() - started)); } catch (Exception e) { System.out.println("Couldn't close con: " + e); } } synchronized(this) { System.out.println("WAITING..."); wait(waitTime); } } } catch (Exception e) { e.printStackTrace(); } } private Connection getConnection() throws SQLException { // load the PoolMan JDBC Driver try { Class.forName("com.codestudio.sql.PoolMan").newInstance(); } catch (Exception ex) { System.out.println("Could Not Find the PoolMan Driver. " + "Is PoolMan.jar in your CLASSPATH?"); System.exit(0); } return DriverManager.getConnection("jdbc:poolman://testdb"); } private Context getContext() throws NamingException { return new InitialContext(); /* final Properties props = new Properties(); props.setProperty(Context.INITIAL_CONTEXT_FACTORY, // "allaire.ejipt.ContextFactory"); "org.jnp.interfaces.NamingContextFactory"); props.setProperty(Context.PROVIDER_URL, // "ejipt://localhost:2323"); "localhost:1099"); return new InitialContext(props); */ }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -