<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Exception thrown while @Timeout is invoked
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/arnosgh">Arnab Ghosh</a> in <i>EJB3 Development</i> - <a href="https://community.jboss.org/message/746747#746747">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi All,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have implemented a statlessBean with Timer service. The timer is getting created without any issue, but when the @Timeout method is getting invoked I am getting the below excetion:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> ERROR [org.jboss.ejb.txtimer.TimerImpl] (EJB-Timer-ee98a936-c65a-4bbb-b697-93f88ca37f1c[target=jboss.j2ee:ear=app.ear,jar=app.backend.jar,name=AssetCreationCompleteTimer,service=EJB3]) Error invoking ejbTimeout</p><p>java.lang.NullPointerException</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.lang.reflect.Method.invoke(Method.java:597)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:682)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:199)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jboss.as.ejb3.timerservice.TimedObjectInvokerBridge.callTimeout(TimedObjectInvokerBridge.java:44)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jboss.ejb.txtimer.TimerImpl$TimerTaskImpl.run(TimerImpl.java:664)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.util.TimerThread.mainLoop(Timer.java:512)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.util.TimerThread.run(Timer.java:462)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My looks like:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>@Stateless</p><p>@LocalBinding(jndiBinding = "com.app.backend.maintenance.AssetCreationCompleteTimerLocal")</p><p>public class AssetCreationCompleteTimer implements AssetCreationCompleteTimerLocal {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; @PersistenceContext(unitName = "unitName")</p><p>&#160; private EntityManager entityManager;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; @Resource(mappedName = "java:/JmsXA")</p><p>&#160; private QueueConnectionFactory queueConnectionFactory;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; private final Logger log = LoggerFactory.getLogger(getClass());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; @Resource</p><p>&#160; private SessionContext sessionContext;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; @Override</p><p>&#160; public void scheduleNextExecution(Date dateToExecute, boolean isCancelExisting) {</p><p>&#160;&#160;&#160; TimerService timerService = sessionContext.getTimerService();</p><p>&#160;&#160;&#160; for (Object o : timerService.getTimers()) {</p><p>&#160;&#160;&#160;&#160;&#160; if (o instanceof Timer) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Timer timer = (Timer) o;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // if current Date is greater than or after the existing timers next run date, cancel inactive timer</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (new Date().after(timer.getNextTimeout())) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; timer.cancel();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; continue;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // if date to schedule next run is less than or before the existing timers next run date, cancel the current timer</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // only if isCancelExisting is set to true. This done to ensure that timers don't get re-scheduled on an earlier date unless specifically intended.</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (dateToExecute.before(timer.getNextTimeout())) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info(String.format("%s job is already scheduled for %tc", getClass().getSimpleName(), timer.getNextTimeout()));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (isCancelExisting) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.info(String.format("Cancelling the timer for %s which was scheduled to run at %tc ...", getClass().getSimpleName(), timer.getNextTimeout()));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; timer.cancel();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; if (timerService.getTimers().isEmpty()) {</p><p>&#160;&#160;&#160;&#160;&#160; log.info("Creating Timer with Date {} : Class {}", dateToExecute, getClass().getSimpleName());</p><p>&#160;&#160;&#160;&#160;&#160; timerService.createTimer(dateToExecute, null);</p><p>&#160;&#160;&#160;&#160;&#160; log.info("Timer created for Class : {}", getClass().getSimpleName());</p><p>&#160;&#160;&#160; }</p><p>&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; @Timeout</p><p>&#160; public void onTimeOut(Timer timer) {</p><p>&#160;&#160;&#160; log.info("Timeout triggered ....");</p><p>&#160;&#160;&#160; Calendar nextRun = Calendar.getInstance();</p><p>&#160;&#160;&#160; nextRun.add(Calendar.MINUTE, 0);</p><p>&#160;&#160;&#160; nextRun.add(Calendar.SECOND, getExecutionIntervalSeconds());</p><p>&#160;&#160;&#160; //String message = String.format("Next execution scheduled for %tc", nextRun);</p><p>&#160;&#160;&#160;&#160;&#160; log.info("Starting execution of {}", getClass().getSimpleName());</p><p>&#160;&#160;&#160;&#160;&#160; execute(); // exceute logic</p><p>&#160; }</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My application is deployed in JBOSS 5.1.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Please help.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Regards</p><p>Arnab</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/746747#746747">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2030">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>