Hi Vimalan,

I tested this problem with a 2000 consecutive requests in Geronimo v 1.1.1. But it doesn't happen to me at all. You can test it with the EJB samples application in http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html replacing following files. We might able to help you if you are more specific and share your code with us.

Regards,
Lasantha Ranaweera

Arunanthisivam Vimalathithen wrote:
Hi,
 
I am having a problem in an application I am trying to port to WebSphere community edition which basically uses Geronimo 1.0 (This problem exists in the latest version of Geronimo (1.1.1) as well). The client I am using looks up the service numerous times consecutively and invokes the services. The problem happens when this has gone past more than 630 times, the client simply fails to look up and produces the following error:
 
java.rmi.RemoteException: Cannot access server: /127.0.0.1:4201 Exception: ; nested exception is: java.io.IOException: Cannot access server: /127.0.0.1:4201 Exception: java.net.BindException : Address already in use: connect
 
The same error can be produced by looking up and invoking a simple hello world EJB in a loop of 700 times. This happens in the latest release of Geronimo (sometimes the loop might need to be increased to 1000). Any work arounds to this?
 
Thanks and regards,
 
Vimalan


package org.apache.geronimo.samples.bank.client;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import org.apache.geronimo.samples.bank.ejb.BankManagerFacade;
import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHome;
import org.apache.geronimo.samples.bank.util.PropertyLoader;

/**
 * 
 * @author Lasantha Ranaweera
 *
 */

public class MainUI extends JFrame implements ActionListener{
	JLabel lblAccountNumber;
	JLabel lblBalance;
	JTextField txtAccountNumber;
	JTextField txtBalance;
	JButton btnView;
	JButton btnUpdate;
	
	BankManagerFacade bankManager = null;
	
	private static final String FACTORY_INITIAL = "java.naming.factory.initial";
	private static final String PROVIDER_URL = "java.naming.provider.url";
	private static final String SECURITY_PRINCIPAL = "java.naming.security.principal";
	private static final String SECURITY_CREDENTIALS = "java.naming.security.credentials";
	private static final String JNDI_BANK_MANAGER = "jndi.bankManager";
	
	private static String CLIENT_PROP_FILE = "bank_client.properties";
	
	
	
	public MainUI(){
		
		super("Banking Remote Application");
		this.setSize(300,190);
		this.getContentPane().setLayout(null);
		
		lblAccountNumber = new JLabel("Account Number");
		lblBalance = new JLabel("Balance");
		txtAccountNumber = new JTextField();
		txtBalance = new JTextField();
		btnView = new JButton("View");
		btnView.addActionListener(this);
		btnUpdate = new JButton("Update");
		btnUpdate.addActionListener(this);
		
		lblAccountNumber.setBounds(10,10,150,40);
		lblBalance.setBounds(10,60,150,40);
		txtAccountNumber.setBounds(180,10,100,40);
		txtBalance.setBounds(180,60,100,40);
		btnView.setBounds(10,110,130,40);
		btnUpdate.setBounds(150,110,130,40);
		
		this.getContentPane().add(lblAccountNumber);
		this.getContentPane().add(lblBalance);
		this.getContentPane().add(txtAccountNumber);
		this.getContentPane().add(txtBalance);
		this.getContentPane().add(btnView);
		this.getContentPane().add(btnUpdate);
		
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((d.width-this.getWidth())/2, (d.height-this.getHeight())/2);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		this.setVisible(true);
		
		try {
			connect();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this,"Initialization Failed !!");
			e.printStackTrace();
		}
	}
	
	
	private void connect() throws Exception {
		
		PropertyLoader propLoader = PropertyLoader.getInstance(CLIENT_PROP_FILE);

		Hashtable env = new Hashtable();
		
		env.put(FACTORY_INITIAL,propLoader.getValue(FACTORY_INITIAL));
		env.put(PROVIDER_URL,propLoader.getValue(PROVIDER_URL));
		env.put(SECURITY_PRINCIPAL,propLoader.getValue(SECURITY_PRINCIPAL));
		env.put(SECURITY_CREDENTIALS,propLoader.getValue(SECURITY_CREDENTIALS));
		
		javax.naming.InitialContext initialContext = new javax.naming.InitialContext(env);
		
		for(int i=0;i<2000;i++){
		
			Object objRef = initialContext.lookup(propLoader.getValue(JNDI_BANK_MANAGER));
		
			BankManagerFacadeHome bankManagerHome = (BankManagerFacadeHome)objRef;
			bankManager = bankManagerHome.create();	
			System.out.println("Create "+i);
		}
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		new MainUI();
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == btnView){
			
			try {
				String account = txtAccountNumber.getText();
				Double balance = new Double(0);
				for(int i=0;i<2000;i++){
					balance = bankManager.getAccountBalance(account);
				}
				if(balance != null){
					txtBalance.setText(balance.toString());
				}else{
					JOptionPane.showMessageDialog(this,"Account Number Not Found !!");
				}
				
			} catch (Exception e1) {
				JOptionPane.showMessageDialog(this,"Remote Exception !!");
				e1.printStackTrace();
			}
		}else if(e.getSource()== btnUpdate){
			try {
				String account = txtAccountNumber.getText();
				String newBalance = txtBalance.getText();
				
				bankManager.changeAccountBalance(account,new Double(newBalance));
				txtBalance.setText("");
				
			} catch (NumberFormatException e1) {
				JOptionPane.showMessageDialog(this,"Invalid Number Format !!");
				e1.printStackTrace();
			} catch (Exception e1) {
				JOptionPane.showMessageDialog(this,"Remote Exception !!");
				e1.printStackTrace();
			}
		}
	}


}



/**
 * 
 */
package org.apache.geronimo.samples.bank.ejb;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.geronimo.samples.bank.dto.AccountDTO;
import org.apache.geronimo.samples.bank.dto.ExchangeRateDTO;

/**
 * @ejb.bean name="BankManagerFacadeBean"
 *       type="Stateless"
 *       jndi-name="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean"
 *       local-jndi-name="java:comp/env/ejb/BankManagerFacade"
 *       view-type="both"
 *
 * @ejb.permission unchecked="true"
 *
 * @ejb.interface generate="local,remote" local-class="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal" remote-class="org.apache.geronimo.samples.bank.ejb.BankManagerFacade"
 * @ejb.home generate="local,remote" local-class="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHomeLocal" remote-class="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHome"
 * @ejb.util generate="physical"
 * 
 * @ejb.ejb-ref ejb-name="Customer" view-type="local" ref-name="ejb/Customer"
 * @ejb.ejb-ref ejb-name="Account" view-type="local" ref-name="ejb/Account"
 * @ejb.ejb-ref ejb-name="ExchangeRate" view-type="local" ref-name="ejb/ExchangeRate"
 * 
 * @web.ejb-local-ref
 *    name="ejb/BankManagerFacade"
 *    type="Session"
 *    home="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHomeLocal"
 *    local="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal"
 *    link="BankManagerFacadeBean"
 * 
 * @author Lasantha Ranaweera
 */

public class BankManagerFacadeBean implements SessionBean {
	private static int counter = 0;
	
	/**
	 * 
	 * @ejb.interface-method view-type="local"
	 * @return
	 */
	public Collection getAccountInformation(String customerId){
		Context context = null;
		ArrayList accountBeanList = new ArrayList();
		try {
			context = new InitialContext();
			CustomerHomeLocal customerHome = (CustomerHomeLocal)context.lookup(CustomerHomeLocal.JNDI_NAME);
			CustomerLocal customer = customerHome.findByPrimaryKey(customerId);
			Iterator accountIterator = customer.getAccounts().iterator();	
			
			
			while(accountIterator.hasNext()){
				AccountDTO account = new AccountDTO();
				
				AccountLocal accountLocal = (AccountLocal)accountIterator.next();
				account.setAccountNumber(accountLocal.getAccountNumber());
				account.setBalance(accountLocal.getBalance());
				account.setAccountType(accountLocal.getAccountType());
				
				accountBeanList.add(account);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		
		return accountBeanList;
	}
	
	/**
	 * @ejb.interface-method view-type="local"
	 * @return
	 */	
	public Collection getExchangeRates() {
		Context context = null;
		Collection rateList = new ArrayList();
		try {
			context = new InitialContext();
			ExchangeRateHomeLocal exchangeRateHome = (ExchangeRateHomeLocal)context.lookup(ExchangeRateHomeLocal.JNDI_NAME);
			Collection rates = exchangeRateHome.findByAll();
			
			Iterator ratesIterator = rates.iterator();
			
			while(ratesIterator.hasNext()){
				ExchangeRateLocal exRate = (ExchangeRateLocal)ratesIterator.next();
				ExchangeRateDTO rateDTO = new ExchangeRateDTO();
				
				rateDTO.setRateId(exRate.getRateId());
				rateDTO.setCurrency(exRate.getCurrency());
				rateDTO.setRate(exRate.getRate());
				
				rateList.add(rateDTO);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		return rateList;
	}

	
	/**
	 * @ejb.interface-method view-type="local"
	 * @param customerCode
	 * @return
	 */
	public CustomerLocal getCustomer(String customerCode){
		Context context = null;
		CustomerLocal customer = null;
		
		try {
			context = new InitialContext();
			CustomerHomeLocal customerHome = (CustomerHomeLocal)context.lookup(CustomerHomeLocal.JNDI_NAME);
			customer  = customerHome.findByPrimaryKey(customerCode);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		return customer;
	}

	
	/**
	 * @ejb.interface-method view-type="remote"
	 * @param accountNo
	 * @param balance
	 */
	public void changeAccountBalance(String accountNo,Double balance){
		Context context = null;
		
		try {
			context = new InitialContext();
			AccountHomeLocal accountHome = (AccountHomeLocal)context.lookup(AccountHomeLocal.JNDI_NAME);
			AccountLocal account = accountHome.findByPrimaryKey(accountNo);
			account.setBalance(balance);			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	/**
	 * @ejb.interface-method view-type="remote"
	 * @param accountNo
	 */
	public Double getAccountBalance(String accountNo){
		System.out.println("Asking for Account Balance");
		Context context = null;
		Double balance = null;
		try {
			context = new InitialContext();
			AccountHomeLocal accountHome = (AccountHomeLocal)context.lookup(AccountHomeLocal.JNDI_NAME);
			AccountLocal account = accountHome.findByPrimaryKey(accountNo);
			balance = account.getBalance();			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		return balance;
	}
	
	/**
	 * @ejb.create-method
	 * 
	 */
	public void ejbCreate() throws javax.ejb.CreateException {
		counter++;
		System.out.println("EJB Create "+counter);
	}

	public void ejbPostCreate() throws javax.ejb.CreateException {
	}

	protected javax.ejb.SessionContext context = null;

	public void setSessionContext(javax.ejb.SessionContext ctx) {
		this.context = ctx;
	}

	protected javax.ejb.SessionContext getSessionContext() {
		return this.context;		
	}

	public void ejbActivate() throws EJBException, RemoteException {

	}

	public void ejbPassivate() throws EJBException, RemoteException {

	}

	public void ejbRemove() throws EJBException, RemoteException {
		counter--;
		System.out.println("EJB Remove"+counter);
	}

}



Reply via email to