Indirect JDBC calls, rethrowable
Another exception such as RetryItException can be rethrown so that you can catch it and retry it in your clients. A segment of code sample is shown in Example 12-4.
Example 12-4 StaleConnectionException with indirect JDBC calls and rethrowable
public class RetryEJBBean implements EntityBean {private javax.ejb.EntityContext entityContext = null;private final static long serialVersionUID = 3206093459760846163L;
public void update(String name) throws RetryItException, RometeException{try {conn=ds.getConnection();conn.setAutoCommit(false);stmt=conn.createStatement();stmt.execute(sqlstring1);} catch (com.ibm.ce.cm.StaleConnectionException sce) {getEntityContext().setRollbackOnly();throw new RetryItException(sce.getMessage());} catch (SQLException sqlex) {...}...}
public class RetryEJBClient {
public static void main(java.lang.String[] args) {//this also can be a part of session beanboolean retry=false;int maxRetries=5;int retryNum=0;do {try {RetryEJB thisEJB=retryEJBHome.findByPrimaryKey(aKey);thisEJB.update(newName);} catch (RetryItException rex) {if (retryNum < maxRetries) {retry=true;retryNum++;} else {retry=false;}try {Thread.sleep (1000);} catch (InterruptedException iex) {}} catch (Exception ex) {}} while (retry);}}
Prev | Home | Next WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.
IBM is a trademark of the IBM Corporation in the United States, other countries, or both.