<!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="http://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;">
    EJB 3.1 Timer problems in scheduling recurring task
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/andrea-b">Andrea Bennati</a> in <i>EJB3</i> - <a href="http://community.jboss.org/message/579029#579029">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I'm trying to use an EJB 3.1 Timer to schedule a recurring task every 5 minutes.</p><p>I'm using JBOSS 6.0.0.Final.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This is the simple code I have deployed:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.ejb.Schedule;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.ejb.Stateless;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">import javax.ejb.Timeout;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">/**</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> * Session Bean implementation class AlerMonitorBean</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> */</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@Stateless</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class AlerMonitorBean {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; /**</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160; * Default constructor. </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160; */</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; public AlerMonitorBean() {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated constructor stub</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; @Schedule(minute="0/5")</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; public void GestisciAlert() {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println("Gestisti Alert - Tick"+System.currentTimeMillis());</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; @Timeout</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; public void GestisciTimeout(){</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;System.out.println("Timeout");</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> }</p></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></div><p>import javax.ejb.Schedule;</p><p>import javax.ejb.Stateless;</p><p>import javax.ejb.Timeout;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>/**</p><p> * Session Bean implementation class AlerMonitorBean</p><p> */</p><p>@Stateless</p><p>public class AlerMonitorBean {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; /**</p><p>&#160;&#160;&#160;&#160; * Default constructor. </p><p>&#160;&#160;&#160;&#160; */</p><p>&#160;&#160;&#160; public AlerMonitorBean() {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated constructor stub</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Schedule(minute="*/5")</p><p>&#160;&#160;&#160; public void GestisciAlert() {</p><p>&#160;&#160;&#160; <span style="white-space:pre"> </span>System.out.println("Gestisti Alert - Tick -&gt; "+System.currentTimeMillis());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; //TODO: insert code</p><p>&#160;&#160;&#160; }&#160;&#160;&#160; </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I notice the following in Jboss Console:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><p>15:40:00,006 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238400006</p><p>15:40:00,010 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238400010</p><p>15:40:01,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238401004</p><p>15:40:02,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238402004</p><p>15:40:03,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238403004</p><p>15:40:04,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238404004</p><p>15:40:05,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238405004</p><p>15:40:06,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238406004</p><p>15:40:07,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238407004</p><p>15:40:08,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238408003</p><p>15:40:09,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238409004</p><p>15:40:10,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238410003</p><p>15:40:11,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238411004</p><p>15:40:12,006 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238412006</p><p>15:40:13,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238413004</p><p>15:40:14,008 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238414008</p><p>15:40:15,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238415004</p><p>15:40:16,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238416004</p><p>15:40:17,008 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238417008</p><p>15:40:18,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238418004</p><p>15:40:19,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238419003</p><p>15:40:20,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238420004</p><p>15:40:21,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238421003</p><p>15:40:22,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238422004</p><p>15:40:23,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238423003</p><p>15:40:24,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238424004</p><p>15:40:25,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238425003</p><p>15:40:26,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238426004</p><p>15:40:27,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238427003</p><p>15:40:28,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238428004</p><p>15:40:29,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238429004</p><p>15:40:30,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238430004</p><p>15:40:31,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238431004</p><p>15:40:32,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238432004</p><p>15:40:33,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238433004</p><p>15:40:34,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238434004</p><p>15:40:35,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238435004</p><p>15:40:36,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238436004</p><p>15:40:37,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238437004</p><p>15:40:38,005 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238438005</p><p>15:40:39,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238439004</p><p>15:40:40,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238440003</p><p>15:40:41,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238441004</p><p>15:40:42,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238442004</p><p>15:40:43,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238443004</p><p>15:40:44,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238444004</p><p>15:40:45,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238445004</p><p>15:40:46,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238446004</p><p>15:40:47,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238447004</p><p>15:40:48,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238448004</p><p>15:40:49,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238449004</p><p>15:40:50,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238450003</p><p>15:40:51,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238451003</p><p>15:40:52,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238452004</p><p>15:40:53,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238453004</p><p>15:40:54,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238454003</p><p>15:40:55,008 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238455008</p><p>15:40:56,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238456004</p><p>15:40:57,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238457003</p><p>15:40:58,004 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238458004</p><p>15:40:59,003 INFO&#160; [STDOUT] Gestisti Alert - Tick -&gt; 1294238459003</p></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I expected that method "GestisciAlert" was called <span style="text-decoration: underline;">once</span> every 5 minutes.....</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Every 5 minutes Timer starts and activates target method several times (about once per second) for a minute....</p><p>Then it stops and starts again after 4 minutes.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Hope someone can help me.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Andrea</p></div>

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


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

</div>

</body>
</html>