• Post Reply Bookmark Topic Watch Topic
  • New Topic

CMP Problem.  RSS feed

 
Sami Casab
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi EveryBody:
Im having problems with concurrent cmp entity beans y BES 5.2.
I have a SesionBean with a method called getNextPk(). This method finds an
entity bean using findByPrimaryKey method and set a new value with a one of
the EntityBean set Methods. In the table asociated with the entity bean i
have only one record with two fields, prmary key and nextValue, each field
with start value of 1. If i call the getNextPk method from one client
everithing works fine, but if i call the method from 5 difernt concurrent
clients the app server creates 5 diferent instances of my entity bean? this
is normal? i never call a create method and i have only one record on my
table.... .I dont know if this is normal, but the problem is when i set a
new value in the entity bean because the other 4 instances doesnt get the
new value never. Is like the container and/or the entitybean doesnt know
than the data was changed for other entity bean instance.
This a BES cmp bug? This is normal? if this is normal how can i tell a cmp
bean than it need to store the data in the database an refresh the other
bean instances?
I turned off the Entitybean cache options.

Any Help will be appreciated, this is the main code of my application:

//*************This is my SesionBean:

import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
public class GeneradorBean implements SessionBean {
SessionContext sessionContext;
private GenPkHome genPkHome;
private PruebaRemoteHome pruebaRemoteHome = null;

public void ejbCreate() throws CreateException {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
try {
javax.naming.Context context = new javax.naming.InitialContext();
Object ref = context.lookup("PruebaRemote");
pruebaRemoteHome = (PruebaRemoteHome) PortableRemoteObject.narrow(ref,
PruebaRemoteHome.class);
} catch(javax.naming.NamingException e) {
throw new javax.ejb.EJBException(e);
}
}
public int getNuevoNextPk() {
PruebaRemote pruebaRemote = null;
int regreso=0;
try {
pruebaRemote = pruebaRemoteHome.findByPrimaryKey(new Integer(1));
for (int ix=0; ix<100;ix++){
Integer valorActual = pruebaRemote.getValor();
pruebaRemote.setValor(new Integer( valorActual.intValue()+1) );}
regreso=pruebaRemote.getValor().intValue();
} catch(Exception ex) {
ex.printStackTrace();
}

return regreso;
}
}
//**** THIS IS MY ENTITYBEAN
package servidor;
import javax.ejb.*;
abstract public class PruebaBean implements EntityBean {
EntityContext entityContext;
public java.lang.Integer ejbCreate(java.lang.Integer llave) throws
CreateException {
setLlave(llave);
return null;
}
public void ejbPostCreate(java.lang.Integer llave) throws CreateException
{
/**@todo Complete this method*/
}
public void ejbRemove() throws RemoveException {
/**@todo Complete this method*/
}
public abstract void setLlave(java.lang.Integer llave);
public abstract void setValor(java.lang.Integer valor);
public abstract java.lang.Integer getLlave();
public abstract java.lang.Integer getValor();
public void ejbLoad() {
/**@todo Complete this method*/
}
public void ejbStore() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
}
public void ejbPassivate() {
/**@todo Complete this method*/
}
public void unsetEntityContext() {
this.entityContext = null;
}
public void setEntityContext(EntityContext entityContext) {
this.entityContext = entityContext;
}
}

//*********************Finally this is my testClient, i control the number
of threads with the MAX variable.
package test;
import cliente.DmCliente;
import servidor.*;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
import javax.ejb.*;

public class GeneradorTestClient2 extends Thread {
String nombre;
Generador generador;
GeneradorHome generadorHome;
public GeneradorTestClient2() {
try {
Context context = new InitialContext();
Object object = context.lookup("Generador");
generadorHome = (GeneradorHome) PortableRemoteObject.narrow(object,
GeneradorHome.class);
generador = generadorHome.create();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
public void serNombre(String nombre){
this.nombre = nombre;
}
public void run() {
for(int i = 0; i < 4; i++) {
try {
System.out.println(nombre + " " + generador.getNuevoNextPk());
} catch(RemoteException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) {
int MAX = 5; //********Number of max Threads
for(int i = 1; i <= MAX; i++) {
GeneradorTestClient2 x = new GeneradorTestClient2();
x.serNombre("N"+i);
x.start();
}
}
}

 
Diana Finis
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sami,
I'm a little bit new to it, but I have a question
Do your setter/getter methods set/getValor() participate in transaction? (Defined in DD).
 
Sami Casab
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Diana:
Thanksfor the help, but i this methods are part of the transaction, is a very strange situation.
Chears.
 
Diana Finis
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you submit an output of the program?
And also part if DD where you define transaction types for session bean & entity bean?
It looks to me that it's related to transaction settings. The fact that other clients (running in other transactions) do not see the new value, could mean that transactions are not commited when they should.
This is interesting...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!