User: mnf999 Date: 01/06/25 18:08:50 Added: src/main/org/jboss/test/threading/mbean Threads.java ThreadsMBean.java Log: We need to test the caches for locking behaviour. This is an MBean and a EJB with different sorts of methods that will stress the cache mechanisms. Revision Changes Path 1.1 jbosstest/src/main/org/jboss/test/threading/mbean/Threads.java Index: Threads.java =================================================================== /* * JBoss, the OpenSource EJB server * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.test.threading.mbean; import javax.naming.InitialContext; import org.jboss.test.threading.interfaces.EJBThreads; import org.jboss.test.threading.interfaces.EJBThreadsHome; import java.util.Random; /** * This test is there to make sure that the multithreaded version doesn't lock the container * It works in VM and spawns many threads that will ping the server. * * @see <related> * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a> * @version $Revision: 1.1 $ * * Revisions: * * 20010524 marc fleury: Initial version */ public class Threads implements ThreadsMBean { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- private int numberOfThreads = 0; private int loops = 10; private long wait = 100; public boolean runMe = true; private Random random = new Random(); private Runnable test; // Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- public void setWait(long wait) {this.wait = wait;} public long getWait() {return wait;} public void setLoops(int loops) {this.loops = loops;} public int getLoops() {return loops;} public void setNumberOfThreads(int numberOfThreads) { if (this.numberOfThreads > 0) stopMe(); this.numberOfThreads=numberOfThreads; //restart try { if (numberOfThreads> 0) startMe(); } catch (Exception e) { e.printStackTrace(); } } public int getNumberOfThreads() { return numberOfThreads;} public void startMe() throws Exception { runMe = true; if (numberOfThreads >0) { for (int i = 0; i < numberOfThreads ; i++) { Thread t = new Thread(new Test()); System.out.println("started new thread " +t.hashCode()); t.start(); }; } } public void stopMe() { System.out.println("Stop called"); runMe = false; }; public class Test implements Runnable { public void run() { try { InitialContext ic = new InitialContext(); EJBThreadsHome testHome = (EJBThreadsHome) ic.lookup("threads"); EJBThreads ejbTest; while(runMe) { try { ejbTest = testHome.findByPrimaryKey("test1"); } catch (Exception e) { // Bean wasn't found create it ejbTest = testHome.create("test1"); } try { // get a random value between 1 and 100 int value = random.nextInt(100); // 10% removal if (value <40) { ejbTest.remove(); } // 40% normal else if (value<41) { ejbTest.test(); } // 20% business exception else if (value<42) { ejbTest.testBusinessException(); } // 20 % runtime excpetion else if (value <90) { ejbTest.testRuntimeException(); } // 10% timeout else { ejbTest.testTimeOut(); } synchronized (this) { //Thread.currentThread().yield(); wait(wait); } }catch (Exception e) {} } } catch (Exception e) {e.printStackTrace();} } } } 1.1 jbosstest/src/main/org/jboss/test/threading/mbean/ThreadsMBean.java Index: ThreadsMBean.java =================================================================== /* * JBoss, the OpenSource EJB server * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.test.threading.mbean; /** * <description> * * @see <related> * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a> * @version $Revision: 1.1 $ * * Revisions: * * 20010625 marc fleury: Initial version */ public interface ThreadsMBean { public void setNumberOfThreads(int numberOfThreads) ; public int getNumberOfThreads(); public void setWait(long numberOfThreads) ; public long getWait(); public void startMe() throws Exception; public void stopMe(); } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development