Matt Cleveland wrote:
We're running 9.2.0.1.  Your test passes.  There must be something else
going on.  Any ideas?  I can submit a bug if I need to.

I just ran 50 threads calling into an EJB that inserts a record into a database. This test ran for about half an hour and created about 52000 records without any exception whatsoever. I am using JBoss 3.2 from cvs (no cluster, though), win2k sp2, jdk 1.4.1_01, classes12.zip from 9201 distribution; oracle 9.2.0.1 under solaris 8.

Attached is my test SSB and its client. If this test ejb fails in your environment (make sure you do not run cluster) then... well, there is not much I can do. If this test works, try to make it fail with XAER_RMERR by changing JBoss configuration and SSB.

--
Igor Fedorenko
Think smart. Think automated. Think Dynamics.
www.thinkdynamics.com
package simple.ejb;

import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * @author ifedorenko
 * 
 * @ejb:bean type="Stateless" name="test/Test"
 *      jndi-name="ejb/test/Test"
 * @ejb:transaction type="Required"
 *
 * @ejb:resource-ref res-name="jdbc/OracleDS" res-type="javax.sql.DataSource"
 *         res-auth="Container"
 * 
 * @jboss:resource-ref res-ref-name="jdbc/OracleDS" jndi-name="java:/XAOracleDS"
 */
public class TestBean implements SessionBean {

    /**
     * 1. Gets JDBC connection
     * 2. Updates DB
     * 
     * @ejb:interface-method
     */
    public String getTest() {
        Connection conn = null; 
        try {
            // get jdbc connection
            conn = makeConnection();
//            conn.setAutoCommit(false);
//            conn.rollback();
//            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            // jdbc update
            Statement stmt = conn.createStatement();
            try {
                stmt.executeUpdate("insert into test(f1) values (to_char(sysdate, 
'dd:mm:yyyy'))");
            } finally {
                stmt.close();
            }
            return "Something else";
        } catch (SQLException e) {
            throw new EJBException(e); 
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                throw new EJBException(e); 
            }
        }
    }

    protected Connection makeConnection() {
        Context ctx = null;
        DataSource ds = null;
        try {
            ctx = new InitialContext();
            ds = (DataSource) ctx.lookup("java:comp/env/jdbc/OracleDS");
            Connection conn = ds.getConnection();
            return conn;
        } catch (NamingException e) {
            throw new EJBException(e);
        } catch (SQLException e) {
            throw new EJBException(e);
        } finally {
            try {
                if (ctx != null) {
                    ctx.close();
                }
            } catch (NamingException e) {
                throw new EJBException(e);
            }
        }
    }

    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#ejbActivate()
     */
    public void ejbActivate() throws EJBException, RemoteException {
    }


    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#ejbPassivate()
     */
    public void ejbPassivate() throws EJBException, RemoteException {
    }


    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#ejbRemove()
     */
    public void ejbRemove() throws EJBException, RemoteException {
    }


    /* (non-Javadoc)
     * @see javax.ejb.SessionBean#setSessionContext(SessionContext)
     */
    public void setSessionContext(SessionContext arg0)
        throws EJBException, RemoteException {
    }

    public void ejbCreate() {
    }

}

package simple.ejb.client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import simple.ejb.Test;
import simple.ejb.TestHome;

/**
 * @author ifedorenko
 */
public class TestMtClient implements Runnable {

    public void run() {
        try {
            for (int i = 0; ; i++) {
                if ((i % 10) == 0) {
                    System.out.println(Thread.currentThread().getName() + ": " + i);
                }
                Context ctx = new InitialContext();
                Object objRef = ctx.lookup("ejb/test/Test");
                TestHome home = (TestHome) 
                        PortableRemoteObject.narrow(objRef, TestHome.class);
                Test bean = home.create();
                try {
                    bean.getTest();
                } finally {
                    bean.remove();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {
        int max = 50;
        for (int i = 0; i < max; i++) {
            new Thread(new TestMtClient()).start();
        }
    }
}

Reply via email to