...
To create a multithreaded process, you need to create two process classes extending com.crm.process.CRMProcessRunBean implementing at least one method each. The first one (main) will be used to create and run new threads and the second one will implement the business logic executed by a thread.
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public class CRMProcessAccountBilling extends CRMProcessRunBean { ... public void billAccounts(Integer threads,String logFileName) throws Exception { ResultSetUtil billableAccounts = getBillableAccounts(); Integer threads = getNumberOfThreads(); Boolean logFailed = new Boolean(true); Boolean logSuccess = new Boolean(true); if (billableAccounts != null && billableAccounts.getRowCount()>0) { EJBThreadPoolExecutor threadExecutor=new EJBThreadPoolExecutor(getCRMSessionHandle(), "ejb/CRMProcessBillAccount", "billAccount",threads, billableAccounts.getRowCount(), 10, TimeUnit.SECONDS, logFileName); while (billableAccounts.next()) { String accRecID = billableAccounts.getString("ACCRECID"); Object[] otherparams = new Object[] {accRecID}; threadExecutor.submitTask(otherparams); } threadExecutor.shutdown(); } } ... } |
Note that the default transaction timeout value of the main process class, which in this case is CRMProcessAccountBillingBean, must be increased. For more information on setting EJB transactions timeout value go to Change EJB Transaction Timeout.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
public class CRMProcessBillAccountextends CRMProcess { ... @EJB private CRMProcessLog processLog; ... public void billAccount(String accrecID, CRMDOProcessRunLog processRun, Boolean logSuccess, Boolean logFailed) throws Exception { try { //put the code to bill the account here ... ... } catch(Exception e) { //log the error details here ... ... //Rollback the changes getSessionContext().setRollbackOnly(); } } ... } |