我新的EJB,并尝试写EJB状态bean一个实现,但是当我尝试做交易的返回象一个无豆状态bean行为就像一个无状态的bean
package beanpackage;
import javax.ejb.Stateful;
//import javax.ejb.Stateless;
/**
* Session Bean implementation class bankbean
*/
@Stateful
public class bankbean implements bankbeanRemote, bankbeanLocal {
/**
* Default constructor.
*/
static int accountbalance;
public bankbean() {
accountbalance=10;
}
public int accountbalancecheck()
{
return accountbalance;
}
public int accountwithdraw(int amount)
{
return (accountbalance-amount);
}
public int accountdeposit(int amount)
{
return (accountbalance+amount);
}
}
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import beanpackage.bankbeanRemote;
public class appclient {
public static void main(String args[]) throws NamingException
{
Context c = appclient.getIntitialContext();
bankbeanRemote bbr = (bankbeanRemote)c.lookup("bankbean/remote");
int s = bbr.accountbalancecheck();
System.out.print(s+" this is first ejb output");
s=bbr.accountwithdraw(1);
System.out.print(s+" this is first ejb output");
s=bbr.accountwithdraw(1);
System.out.print(s+" this is first ejb output");
}
public static Context getIntitialContext() throws NamingException
{
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
prop.setProperty("java.naming.provider.url", "127.0.0.1:1099");
return new InitialContext(prop);
}
}
输出是:
10 this is first ejb output
9 this is first ejb output
9 this is first ejb output
我听不懂。它应该返回109,然后返回8..but 10 9 9..please帮助