jQuery in Action, 2nd edition*
The moose likes JBoss/WildFly and the fly likes Out of Memory when testing a BMP Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Out of Memory when testing a BMP Bean" Watch "Out of Memory when testing a BMP Bean" New topic
Author

Out of Memory when testing a BMP Bean

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Ladies and gentlemen,
I have been able to deploy a BMP bean, and deploy it to JBoss. I�m writing code to stress is, the result of it have not been very satistfactory.
I have created a BMP entity bean called product. I have put together a Java client that tells to the home interface of the bean to create 100000 objects.
When arriving to the object 62000 approx., an "out of memory" error comes up.
I do not know if that�s because this is not the way I am supposed to stress the product, or what. If you guys have ans answer for this, please answer. I have the error message that my client shows, and the code that I use for the strees test.
Thanks much to all!
---------------- Error ----------------------------------
java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.OutOfMemoryError
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:289)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
60)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:701)
at java.lang.Thread.run(Thread.java:534)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Sour
ce)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvo
kerProxy.java:135)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.jav
a:87)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:4
5)
at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:173)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy2.create(Unknown Source)
at test.client.TestClient.main(TestClient.java:49)
Caused by: java.lang.OutOfMemoryError
---------------------- Code for the stress test -------------------------
package test.client;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import test.interfaces.ProductHome;
import test.interfaces.ProductPK;
import test.interfaces.ProductData;
import test.interfaces.Product;
public class TestClient {
public static void main(String[] args){
try {
InitialContext lContext = new InitialContext();

ProductHome prodHome = (ProductHome) lContext.lookup("Product");

ProductData dProduct = new ProductData();

int i = 0;

while (i < 100000) {

dProduct.setProductId(i);
dProduct.setProductName(Integer.toString(i) + ". A name for the bean");
dProduct.setDescription("Description of the bean");
dProduct.setPrice(234);

Product lProduct = prodHome.create(dProduct);

lProduct = null;

i = i + 1;
}



} catch( Exception e ){
e.printStackTrace();
}
}
Claudio Gualberto
Ranch Hand

Joined: Oct 13, 2002
Posts: 47
I think you're better to post the BMP code here, as your container-configuration if it's not the default for BMP.

Claudio Gualberto
SCJP 1.4
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi, Claudio. Thanks for answering.
This is my jboss.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
<jboss>
<enterprise-beans>
<!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jboss-beans.xml that contains
the <session></session>, <entity></entity> and <message-driven></message-driven>
markup for those beans.
-->
<entity>
<ejb-name>User</ejb-name>
<jndi-name>User</jndi-name>
</entity>
<entity>
<ejb-name>Product</ejb-name>
<jndi-name>Product</jndi-name>
<local-jndi-name>ProductLocal</local-jndi-name>
</entity>
<session>
<ejb-name>Adder</ejb-name>
<jndi-name>Adder</jndi-name>
<local-jndi-name>AdderLocal</local-jndi-name>
</session>
</enterprise-beans>
<resource-managers>
</resource-managers>
</jboss>
This is the code used to generate the bean:
import test.interfaces.ProductPK;
import test.interfaces.ProductData;

/**
* The Entity bean represents a TestEntity with BMP
*
* @author Andreas Schaefer
* @version $Revision: 1.1 $
*
* @ejb:bean name="Product"
* display-name="Entity that supports products(BMP)"
* type="BMP"
* jndi-name="Product"
*
* @ejb:env-entry name="DataSourceName"
* value="java:/BelisarioDS"
*
* @ejb:transaction type="Required"
*
* @ejb ata-object extends="test.interfaces.AbstractData"
* setdata="false"
*
**/
public abstract class ProductBean implements EntityBean {

EntityContext context;

int productId;
String productName;
String description;
double price;

// -------------------------------------------------------------------------
// Methods
// -------------------------------------------------------------------------

/**
* Store the data within the provided data object into this bean.
*
* @param pProductBean The Value Object containing the ProductBean values
*
* @ejb:interface-method view-type="remote"
**/
public void setValueObject( ProductData pProductBean )
throws
InvalidValueException
{
setProductId( pProductBean.getProductId() );
setDescription( pProductBean.getDescription() );
setProductName( pProductBean.getProductName() );
setPrice (pProductBean.getPrice());
}

/**
* Create and return a TestEntity data object populated with the data from
* this bean.
*
* @return Returns a TestEntity value object containing the data within this
* bean.
*
* @ejb:interface-method view-type="remote"
**/
public ProductData getValueObject() {
ProductData lData = new ProductData();

lData.setProductId( getProductId() );
lData.setDescription( getDescription() );
lData.setProductName( getProductName() );
lData.setPrice (getPrice());

return lData;
}

/**
* Describes the instance and its content for debugging purpose
*
* @return Debugging information about the instance and its content
**/
public String toString() {
return "TestBMPEntityBean [ " + getValueObject() + " ]";
}

/**
* Mark the Entity as changed that needs to be saved
**/
protected abstract void makeDirty();
/**
* Mark the Entity as synchronized with the DB and does
* not need to be saved
**/
protected abstract void makeClean();

private void save( boolean pIsNew ) {

Connection con = null;
PreparedStatement ps = null;
String sql = null;
try {
if( pIsNew ) {
// Note that the Primary Key "Id" is the last to match the UPDATE statement
sql = "INSERT INTO Products" +
" (ProductName, Description, Price, ProductId)" +
" VALUES" +
" (?, ?, ?, ?)";
}
else
{
sql ="UPDATE Products" +
" SET ProductName=?, Description=?, Price=?" +
" WHERE ProductId=?"; }

con = getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, getProductName());
ps.setString(2, getDescription());
ps.setDouble(3, getPrice());
ps.setInt(4, getProductId());
ps.executeUpdate();
}
catch(SQLException e) {
//System.out.println(e.toString());
throw new EJBException( "Could not save record to DB: " + e.getMessage() );
}
finally
{
try {
if (ps != null)
ps.close();
if (con != null)
con.close();
}
catch (SQLException e ){
}
}

}

// -------------------------------------------------------------------------
// Properties (Getters/Setters)
// -------------------------------------------------------------------------
/**
* Retrieve the Product�s entity ID.
*
* @return Returns an int representing the id of this TestEntity.
*
* @ejb ersistent-field
* @ejb k-field
**/
public abstract int getProductId();

/**
* Set the Product's id.
*
* @param pId The id of this Product. Is set at creation time.
**/
public abstract void setProductId( int pProductId );

/**
* Retrieve the Product�s Name.
*
* @return Returns an int representing the Name of the Product.
*
* @ejb ersistent-field
**/
public abstract String getProductName();

/**
* Set the entity�s Products�s Name.
*
* @param pFirstName The name of the product. Is set at creation time.
**/
public abstract void setProductName( String pProductName );

/**
* Retrieve the Product�s Description.
*
* @return Returns an int representing the Description of the product.
*
* @ejb ersistent-field
**/
public abstract String getDescription();

/**
* Set the TestEntity's LastName.
*
* @param pLastName The description of the product. Is set at creation time.
**/
public abstract void setDescription( String pDescription );

/**
* Retrieve the Product�s Price
*
* @return Returns an int representing the Price of the product.
*
* @ejb ersistent-field
**/
public abstract int getPrice();

/**
* Set the Product�s's LastName.
*
* @param pLastName The priceof the product.
**/
public abstract void setPrice( int pPrice );


// -------------------------------------------------------------------------
// Framework Callbacks
// -------------------------------------------------------------------------

/**
* Create a TestEntity based on the supplied TestEntity Value Object.
*
* @param pTestEntity The data used to create the TestEntity.
*
* @throws InvalidValueException If one of the values are not correct,
* this will not roll back the transaction
* because the caller has the chance to
* fix the problem and try again
* @throws EJBException If no new unique ID could be retrieved this will
* rollback the transaction because there is no
* hope to try again
* @throws CreateException Because we have to do so (EJB spec.)
*
* @ejb:create-method view-type="remote"
**/
public ProductPK ejbCreate( ProductData pProduct )
throws
InvalidValueException,
EJBException,
CreateException
{
// Clone the given Value Object to keep changed private
ProductData lData = (ProductData) pProduct.clone();
// Save the new TestEntity
setValueObject( lData );
save( true );
// Return the PK which is mandatory in BMPs
return new ProductPK( getProductId() );
}

public void ejbPostCreate(ProductData pProduct )
throws RemoteException, CreateException {
//System.out.println("ejbPostCreate");
}

public ProductPK ejbFindByPrimaryKey(ProductPK primaryKey)
throws RemoteException, FinderException {
//System.out.println("ejbFindByPrimaryKey");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT ProductName" +
" FROM Products" +
" WHERE ProductId=?";
con = getConnection();
ps = con.prepareStatement(sql);
int lId = primaryKey.productId;
ps.setInt( 1, lId );
rs = ps.executeQuery();
if (rs.next()) {
rs.close();
ps.close();
con.close();
return primaryKey;
}
}
catch (SQLException e) {
System.out.println(e.toString());
}
finally {
try {
if (rs!=null)
rs.close();
if (ps!=null)
ps.close();
if (con!=null)
con.close();
}
catch (SQLException e) {
}
}
throw new ObjectNotFoundException();
}
public Enumeration ejbFindByName(String name)
throws RemoteException, FinderException {
//System.out.println("ejbFindByName");
Vector products = new Vector();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT ProductId " +
" FROM Products" +
" WHERE ProductName=?";
con = getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, name);
rs = ps.executeQuery();
while (rs.next()) {
int productId = rs.getInt(1);
products.addElement(new ProductPK(getProductId()));
}
}
catch (SQLException e) {
System.out.println(e.toString());
}
finally {
try {
if (rs!=null)
rs.close();
if (ps!=null)
ps.close();
if (con!=null)
con.close();
}
catch (SQLException e) {
}
}
return products.elements();
}
public void ejbRemove() throws RemoveException {
//System.out.println("ejbRemove");
Connection con = null;
PreparedStatement ps = null;
try {
String sql = "DELETE FROM Products" +
" WHERE ProductId=?";
con = getConnection();
ps = con.prepareStatement(sql);
int lId = ( (ProductPK) context.getPrimaryKey() ).productId;
ps.setInt( 1, lId );
ps.executeUpdate();
}
catch (SQLException e) {
throw new RemoveException( "Could not remove record from DB: " + e.getMessage() );
}
finally {
try {
if (ps!=null)
ps.close();
if (con!=null)
con.close();
}
catch (SQLException e) {
}
}
}
public void ejbActivate() {
//System.out.println("ejbActivate");
}
public void ejbPassivate() {
//System.out.println("ejbPassivate");
}
public void ejbLoad() {
//System.out.println("ejbLoad");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT ProductName, Description, Price" +
" FROM Products" +
" WHERE ProductId=?";

con = getConnection();
ps = con.prepareStatement(sql);
int lId = ( (ProductPK) context.getPrimaryKey() ).productId;
ps.setInt( 1, lId );

rs = ps.executeQuery();
if (rs.next()) {
this.productName = rs.getString(1);
this.description = rs.getString(2);
this.price = rs.getDouble(3);
}
makeClean();
}
catch (SQLException e) {
System.out.println(e.toString());
}
finally {
try {
if (rs!=null)
rs.close();
if (ps!=null)
ps.close();
if (con!=null)
con.close();
}
catch (SQLException e) {
}
}
}

public void ejbStore() {
save(false);
}


public void setEntityContext(EntityContext context) {
//System.out.println("setEntityContext");
this.context = context;
}
public void unsetEntityContext() {
//System.out.println("unsetEntityContext");
context = null;
}

public Connection getConnection() {

DataSource myDataSource;

try {
Context lContext = new InitialContext();
String lDataSourceName = (String) lContext.lookup( "java:comp/env/DataSourceName" );
myDataSource = (DataSource) lContext.lookup( lDataSourceName );
return (Connection) myDataSource.getConnection();
}
catch ( NamingException ne ) {
throw new EJBException( "Naming lookup failure: " + ne.getMessage() );
}
catch (SQLException e) {
throw new EJBException( "JDBC Connection failure: " + e.getMessage() );
}

}
}

/*
* Generated by XDoclet - Do not edit!
*/
package test.interfaces;
/**
* Home interface for Product.
*/
public interface ProductHome
extends javax.ejb.EJBHome
{
public static final String COMP_NAME="java:comp/env/ejb/Product";
public static final String JNDI_NAME="Product";
public test.interfaces.Product create(test.interfaces.ProductData pProduct)
throws test.interfaces.InvalidValueException,javax.ejb.CreateException,java.rmi.RemoteException;
public test.interfaces.Product findByPrimaryKey(test.interfaces.ProductPK primaryKey)
throws java.rmi.RemoteException,javax.ejb.FinderException,java.rmi.RemoteException;
public java.util.Enumeration findByName(java.lang.String name)
throws java.rmi.RemoteException,javax.ejb.FinderException,java.rmi.RemoteException;
}
and this the code that XDoclet generates for the Object interface:

*
* Generated by XDoclet - Do not edit!
*/
package test.interfaces;
/**
* Data object for Product.
*/
public class ProductData
extends test.interfaces.AbstractData
implements java.io.Serializable
{
private int productId;
private java.lang.String productName;
private java.lang.String description;
private int price;
public ProductData()
{
}
public ProductData( int productId,java.lang.String productName,java.lang.String description,int price )
{
setProductId(productId);
setProductName(productName);
setDescription(description);
setPrice(price);
}
public ProductData( ProductData otherData )
{
setProductId(otherData.getProductId());
setProductName(otherData.getProductName());
setDescription(otherData.getDescription());
setPrice(otherData.getPrice());
}
public test.interfaces.ProductPK getPrimaryKey() {
test.interfaces.ProductPK pk = new test.interfaces.ProductPK(this.getProductId());
return pk;
}
public int getProductId()
{
return this.productId;
}
public void setProductId( int productId )
{
this.productId = productId;
}
public java.lang.String getProductName()
{
return this.productName;
}
public void setProductName( java.lang.String productName )
{
this.productName = productName;
}
public java.lang.String getDescription()
{
return this.description;
}
public void setDescription( java.lang.String description )
{
this.description = description;
}
public int getPrice()
{
return this.price;
}
public void setPrice( int price )
{
this.price = price;
}
public String toString()
{
StringBuffer str = new StringBuffer("{");
str.append("productId=" + getProductId() + " " + "productName=" + getProductName() + " " + "description=" + getDescription() + " " + "price=" + getPrice());
str.append('}');
return(str.toString());
}
public boolean equals( Object pOther )
{
if( pOther instanceof ProductData )
{
ProductData lTest = (ProductData) pOther;
boolean lEquals = true;
lEquals = lEquals && this.productId == lTest.productId;
if( this.productName == null )
{
lEquals = lEquals && ( lTest.productName == null );
}
else
{
lEquals = lEquals && this.productName.equals( lTest.productName );
}
if( this.description == null )
{
lEquals = lEquals && ( lTest.description == null );
}
else
{
lEquals = lEquals && this.description.equals( lTest.description );
}
lEquals = lEquals && this.price == lTest.price;
return lEquals;
}
else
{
return false;
}
}
public int hashCode()
{
int result = 17;
result = 37*result + (int) productId;
result = 37*result + ((this.productName != null) ? this.productName.hashCode() : 0);
result = 37*result + ((this.description != null) ? this.description.hashCode() : 0);
result = 37*result + (int) price;
return result;
}
}

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Out of Memory when testing a BMP Bean
 
Similar Threads
Entity Bean Problem
Please help me in the cmp problem
How to do connection pooling for cmp?
Calling EJB From the Client
BMP, Jboss, and mysql configuring