Hi everybody! I have written a session bean that performs some sort of polling: Polls a directory to read CSV-formatted files written in there, parse them, and persist their contents to a DB table (by way of an entity bean). Here is what I would like:
(i) I would want to transaction to run forever; I do not want the transaction to time out (ii) Actually, I do not want to have a transaction at all. Every update to the table should be atomic (iii) I need some way to execute the session bean after the application gets deployed to the application server (WebSphere in my case).
I anyone could point me to any material that I could consult in order to address the above issues, I would greatly appreciate it!
Do I understand you right that you are performing IO from a Session Bean? I hope you are doing it through a JCA adapter.
(i) I would want to transaction to run forever; I do not want the transaction to time out
If the transaction never ends, then how is anything ever committed? Also you can't perform file system operations in a transaction - since the file system is not a transactional resource. There are open source projects out there which offer access to it in a transactional way - you might want to google for such a thing if you need it.
(ii) Actually, I do not want to have a transaction at all. Every update to the table should be atomic
OK. Then don't use a transaction.
(iii) I need some way to execute the session bean after the application gets deployed to the application server (WebSphere in my case).
One of the WebSphere components has start up beans - not the application server itself, I think its Application Server Enterprise. You could use them. There is nothing in the J2EE spec. to have a session bean run at startup. You could write it as an MDB and send a message from a servlet configured to load at startup - then whenever the MDB is deployed, it can do whatever you need done.
Thanks Paul! I specified a transaction attribute of NotSupported for the EJBs in question and this works fine for my needs.
Regarding the question of how to execute the method, I am giving a shot to an open-source project named Pulsar (http://sourceforge.net/projects/j2eescheduler/) for my scheduling needs (which aren't too complicated). This works from within the development tool (WSAD), i.e. I can start the server just fine, and the method starts executing; however, it is problematic when I deploy to an actual application server (WebSphere Application Server). In particular I get a ClassCastException, as shown in the stack traces below.
Any help as to how to further investigate this problem would be greatly appreciated...
[21/2/2005 16:31:17:657 EET] 5e8bcd4b ExceptionUtil E CNTR0019E: Non-application exception occurred while processing method "create". Exception data: com.ibm.ejs.container.CreateFailureException: ; nested exception is: java.lang.ClassCastException: com.webage.scheduler.EJSRemoteStatelessCubeIqFilePoller_0c4f2a53 at com.webage.scheduler.EJSStatelessCubeIqFilePollerHomeBean_0c4f2a53.create(EJSStatelessCubeIqFilePollerHomeBean_0c4f2a53.java:32) at com.webage.scheduler.EJSRemoteStatelessCubeIqFilePollerHome_0c4f2a53.create(EJSRemoteStatelessCubeIqFilePollerHome_0c4f2a53.java:35) at com.webage.scheduler._EJBTaskHome_Stub.create(_EJBTaskHome_Stub.java:230) at com.webage.scheduler.Engine.addTask(Engine.java:124) at com.webage.scheduler.Engine.startElement(Engine.java:97) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at com.webage.scheduler.Engine.reloadConfig(Engine.java:41) at com.webage.scheduler.Engine.<init>(Engine.java:26) at com.webage.scheduler.SchedulerServlet.init(SchedulerServlet.java:15) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doInit(StrictServletInstance.java:82) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._init(StrictLifecycleServlet.java:147) at com.ibm.ws.webcontainer.servlet.PreInitializedServletState.init(StrictLifecycleServlet.java:270) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.init(StrictLifecycleServlet.java:113) at com.ibm.ws.webcontainer.servlet.ServletInstance.init(ServletInstance.java:189) at javax.servlet.GenericServlet.init(GenericServlet.java:258) at com.ibm.ws.webcontainer.webapp.WebAppServletManager.addServlet(WebAppServletManager.java:870) at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:224) at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadAutoLoadServlets(WebAppServletManager.java:542) at com.ibm.ws.webcontainer.webapp.WebApp.loadServletManager(WebApp.java:1277) at com.ibm.ws.webcontainer.webapp.WebApp.init(WebApp.java:283) at com.ibm.ws.webcontainer.srt.WebGroup.loadWebApp(WebGroup.java:387) at com.ibm.ws.webcontainer.srt.WebGroup.init(WebGroup.java:209) at com.ibm.ws.webcontainer.WebContainer.addWebApplication(WebContainer.java:987) at com.ibm.ws.runtime.component.WebContainerImpl.install(WebContainerImpl.java:136) at com.ibm.ws.runtime.component.WebContainerImpl.start(WebContainerImpl.java:356) at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:418) at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:787) at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:354) at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:575) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:271) at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:488) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code)) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) at com.tivoli.jmx.modelmbean.MMBInvoker.invoke(MMBInvoker.java:46) at com.tivoli.jmx.modelmbean.MMBInvoker.invokeOperation(MMBInvoker.java:115) at com.tivoli.jmx.modelmbean.DynamicModelMBeanSupport.invoke(DynamicModelMBeanSupport.java:409) at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:323) at com.tivoli.jmx.GenericMBeanSupport.invoke(GenericMBeanSupport.java:178) at com.tivoli.jmx.MBeanAccess.invoke(MBeanAccess.java:113) at com.tivoli.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:290) at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:659) at com.ibm.ws.console.core.mbean.MBeanHelper.invoke(MBeanHelper.java:141) at com.ibm.ws.console.appdeployment.ApplicationDeploymentCollectionAction.perform(ApplicationDeploymentCollectionAction.java:315) at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1791) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313) at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java(Inlined Compiled Code)) at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java(Compiled Code)) at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java(Inlined Compiled Code)) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java(Compiled Code)) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java(Compiled Code)) at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200) at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119) at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276) at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71) at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114) at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186) at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334) at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56) at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618) at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:443) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code)) Caused by: java.lang.ClassCastException: com.webage.scheduler.EJSRemoteStatelessCubeIqFilePoller_0c4f2a53 at com.webage.scheduler.EJSStatelessCubeIqFilePollerHomeBean_0c4f2a53.create(EJSStatelessCubeIqFilePollerHomeBean_0c4f2a53.java:22) ... 77 more [ February 21, 2005: Message edited by: Panagiotis Varlagas ]