<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FEJB3%2FTimer</id>
		<title>Java/EJB3/Timer - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FEJB3%2FTimer"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/EJB3/Timer&amp;action=history"/>
		<updated>2026-04-06T20:53:29Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/EJB3/Timer&amp;diff=7775&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/EJB3/Timer&amp;diff=7775&amp;oldid=prev"/>
				<updated>2010-06-01T06:50:33Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:50, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/EJB3/Timer&amp;diff=7774&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/EJB3/Timer&amp;diff=7774&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== EJB Tutorial from JBoss: timer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
File: ExampleTimer.java&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source.&lt;br /&gt;
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors&lt;br /&gt;
 * as indicated by the @author tags. See the copyright.txt file in the&lt;br /&gt;
 * distribution for a full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
package org.jboss.tutorial.timer.bean;&lt;br /&gt;
&lt;br /&gt;
public interface ExampleTimer&lt;br /&gt;
{&lt;br /&gt;
   void scheduleTimer(long milliseconds);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: ExampleTimerBean.java&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source.&lt;br /&gt;
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors&lt;br /&gt;
 * as indicated by the @author tags. See the copyright.txt file in the&lt;br /&gt;
 * distribution for a full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
package org.jboss.tutorial.timer.bean;&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
import javax.annotation.Resource;&lt;br /&gt;
import javax.ejb.Remote;&lt;br /&gt;
import javax.ejb.SessionContext;&lt;br /&gt;
import javax.ejb.Stateless;&lt;br /&gt;
import javax.ejb.Timeout;&lt;br /&gt;
import javax.ejb.Timer;&lt;br /&gt;
@Stateless&lt;br /&gt;
@Remote(ExampleTimer.class)&lt;br /&gt;
public class ExampleTimerBean implements ExampleTimer&lt;br /&gt;
{&lt;br /&gt;
   private @Resource SessionContext ctx;&lt;br /&gt;
   public void scheduleTimer(long milliseconds)&lt;br /&gt;
   {&lt;br /&gt;
      ctx.getTimerService().createTimer(new Date(new Date().getTime() + milliseconds), &amp;quot;Hello World&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
   @Timeout&lt;br /&gt;
   public void timeoutHandler(Timer timer)&lt;br /&gt;
   {&lt;br /&gt;
      System.out.println(&amp;quot;---------------------&amp;quot;);&lt;br /&gt;
      System.out.println(&amp;quot;* Received Timer event: &amp;quot; + timer.getInfo());&lt;br /&gt;
      System.out.println(&amp;quot;---------------------&amp;quot;);&lt;br /&gt;
      timer.cancel();&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: Client.java&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source.&lt;br /&gt;
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors&lt;br /&gt;
 * as indicated by the @author tags. See the copyright.txt file in the&lt;br /&gt;
 * distribution for a full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
package org.jboss.tutorial.timer.client;&lt;br /&gt;
import org.jboss.tutorial.timer.bean.ExampleTimer;&lt;br /&gt;
import javax.naming.InitialContext;&lt;br /&gt;
&lt;br /&gt;
public class Client&lt;br /&gt;
{&lt;br /&gt;
   public static void main(String[] args) throws Exception&lt;br /&gt;
   {&lt;br /&gt;
      InitialContext ctx = new InitialContext();&lt;br /&gt;
      ExampleTimer timer = (ExampleTimer) ctx.lookup(&amp;quot;ExampleTimerBean/remote&amp;quot;);&lt;br /&gt;
      timer.scheduleTimer(5000);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Timer Service And Timeout Method ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File: EmployeeBean.java&lt;br /&gt;
import javax.annotation.Resource;&lt;br /&gt;
import javax.ejb.SessionContext;&lt;br /&gt;
import javax.ejb.Stateless;&lt;br /&gt;
import javax.ejb.Timeout;&lt;br /&gt;
import javax.ejb.Timer;&lt;br /&gt;
import javax.ejb.TimerService;&lt;br /&gt;
@Stateless&lt;br /&gt;
public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {&lt;br /&gt;
  @Resource&lt;br /&gt;
  private SessionContext ctx;&lt;br /&gt;
  public EmployeeBean() {&lt;br /&gt;
  }&lt;br /&gt;
  public Long addBid(String userId, Long itemId, Double bidPrice) {&lt;br /&gt;
    System.out.println(&amp;quot;Bid for &amp;quot; + itemId + &amp;quot; received with price&amp;quot; + bidPrice);&lt;br /&gt;
    TimerService timerService = ctx.getTimerService();&lt;br /&gt;
    Timer timer = timerService.createTimer(123, 86400000, null);&lt;br /&gt;
    return 0L;&lt;br /&gt;
  }&lt;br /&gt;
  @Timeout&lt;br /&gt;
  public void handleTimeout(Timer timer) {&lt;br /&gt;
    System.out.println(&amp;quot; handleTimeout called.&amp;quot;);&lt;br /&gt;
    // Put here the code for cleaning the database of day limit orders that have&lt;br /&gt;
    // not been executed.&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: EmployeeServiceLocal.java&lt;br /&gt;
&lt;br /&gt;
import javax.ejb.Local;&lt;br /&gt;
import javax.jws.WebParam;&lt;br /&gt;
@Local&lt;br /&gt;
public interface EmployeeServiceLocal {&lt;br /&gt;
  public Long addBid(String userId,Long itemId,Double bidPrice);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: EmployeeServiceRemote.java&lt;br /&gt;
import javax.ejb.Remote;&lt;br /&gt;
&lt;br /&gt;
@Remote&lt;br /&gt;
public interface EmployeeServiceRemote {&lt;br /&gt;
  public Long addBid(String userId,Long itemId,Double bidPrice);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: Employee.java&lt;br /&gt;
&lt;br /&gt;
import javax.persistence.Entity;&lt;br /&gt;
import javax.persistence.GeneratedValue;&lt;br /&gt;
import javax.persistence.Id;&lt;br /&gt;
import javax.persistence.PostRemove;&lt;br /&gt;
@Entity&lt;br /&gt;
public class Employee implements java.io.Serializable {&lt;br /&gt;
  private int id;&lt;br /&gt;
  private String firstName;&lt;br /&gt;
  private String lastName;&lt;br /&gt;
  @Id&lt;br /&gt;
  @GeneratedValue&lt;br /&gt;
  public int getId() {&lt;br /&gt;
    return id;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  @PostRemove&lt;br /&gt;
  public void postRemove()&lt;br /&gt;
  {&lt;br /&gt;
     System.out.println(&amp;quot;@PostRemove&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void setId(int id) {&lt;br /&gt;
    this.id = id;&lt;br /&gt;
  }&lt;br /&gt;
  public String getFirstName() {&lt;br /&gt;
    return firstName;&lt;br /&gt;
  }&lt;br /&gt;
  public void setFirstName(String first) {&lt;br /&gt;
    this.firstName = first;&lt;br /&gt;
  }&lt;br /&gt;
  public String getLastName() {&lt;br /&gt;
    return lastName;&lt;br /&gt;
  }&lt;br /&gt;
  public void setLastName(String last) {&lt;br /&gt;
    this.lastName = last;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: Main.java&lt;br /&gt;
import javax.ejb.EJB;&lt;br /&gt;
import javax.naming.InitialContext;&lt;br /&gt;
&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] a) throws Exception {&lt;br /&gt;
    EmployeeServiceRemote service = null;&lt;br /&gt;
    // Context compEnv = (Context) new InitialContext().lookup(&amp;quot;java:comp/env&amp;quot;);&lt;br /&gt;
    // service = (HelloService)new&lt;br /&gt;
    // InitialContext().lookup(&amp;quot;java:comp/env/ejb/HelloService&amp;quot;);&lt;br /&gt;
    service = (EmployeeServiceRemote) new InitialContext().lookup(&amp;quot;EmployeeBean/remote&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    service.addBid(&amp;quot;userId&amp;quot;,1L,0.1);&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: jndi.properties&lt;br /&gt;
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory&lt;br /&gt;
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces&lt;br /&gt;
java.naming.provider.url=localhost:1099&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Use Timer Service ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File: Employee.java&lt;br /&gt;
import javax.persistence.Entity;&lt;br /&gt;
import javax.persistence.EntityListeners;&lt;br /&gt;
import javax.persistence.GeneratedValue;&lt;br /&gt;
import javax.persistence.Id;&lt;br /&gt;
import javax.persistence.PostRemove;&lt;br /&gt;
@Entity&lt;br /&gt;
public class Employee implements java.io.Serializable {&lt;br /&gt;
  private int id;&lt;br /&gt;
  private String firstName;&lt;br /&gt;
  private String lastName;&lt;br /&gt;
  @Id&lt;br /&gt;
  @GeneratedValue&lt;br /&gt;
  public int getId() {&lt;br /&gt;
    return id;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  @PostRemove&lt;br /&gt;
  public void postRemove()&lt;br /&gt;
  {&lt;br /&gt;
     System.out.println(&amp;quot;@PostRemove&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void setId(int id) {&lt;br /&gt;
    this.id = id;&lt;br /&gt;
  }&lt;br /&gt;
  public String getFirstName() {&lt;br /&gt;
    return firstName;&lt;br /&gt;
  }&lt;br /&gt;
  public void setFirstName(String first) {&lt;br /&gt;
    this.firstName = first;&lt;br /&gt;
  }&lt;br /&gt;
  public String getLastName() {&lt;br /&gt;
    return lastName;&lt;br /&gt;
  }&lt;br /&gt;
  public void setLastName(String last) {&lt;br /&gt;
    this.lastName = last;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: EmployeeService.java&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
import javax.annotation.Resource;&lt;br /&gt;
import javax.ejb.Stateless;&lt;br /&gt;
import javax.ejb.Timeout;&lt;br /&gt;
@Stateless&lt;br /&gt;
public class EmployeeService implements EmployeeServiceLocal, EmployeeServiceRemote {&lt;br /&gt;
  @Resource&lt;br /&gt;
  javax.ejb.TimerService timerService;&lt;br /&gt;
  public EmployeeService() {&lt;br /&gt;
  }&lt;br /&gt;
  public void doAction() {&lt;br /&gt;
    String item = &amp;quot;item 1&amp;quot;;&lt;br /&gt;
    for (Object obj : timerService.getTimers()) {&lt;br /&gt;
      javax.ejb.Timer timer = (javax.ejb.Timer) obj;&lt;br /&gt;
      String scheduled = (String) timer.getInfo();&lt;br /&gt;
      if (scheduled.equals(item)) {&lt;br /&gt;
        timer.cancel();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    timerService.createTimer(new Date(System.currentTimeMillis() + 1000), item);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  @Timeout&lt;br /&gt;
  public void maintenance(javax.ejb.Timer timer) {&lt;br /&gt;
    System.out.println(&amp;quot;TIMEOUT METHOD CALLED&amp;quot;);&lt;br /&gt;
    String scheduled = (String) timer.getInfo();&lt;br /&gt;
    System.out.println(scheduled);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: EmployeeServiceLocal.java&lt;br /&gt;
&lt;br /&gt;
import java.util.Collection;&lt;br /&gt;
import javax.ejb.Local;&lt;br /&gt;
@Local&lt;br /&gt;
public interface EmployeeServiceLocal {&lt;br /&gt;
    public void doAction();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: EmployeeServiceRemote.java&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
import java.util.Collection;&lt;br /&gt;
import javax.ejb.Remote;&lt;br /&gt;
@Remote&lt;br /&gt;
public interface EmployeeServiceRemote{&lt;br /&gt;
  public void doAction();  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
File: jndi.properties&lt;br /&gt;
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory&lt;br /&gt;
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces&lt;br /&gt;
java.naming.provider.url=localhost:1099&lt;br /&gt;
&lt;br /&gt;
File: Main.java&lt;br /&gt;
import java.util.Date;&lt;br /&gt;
import javax.naming.InitialContext;&lt;br /&gt;
&lt;br /&gt;
public class Main {&lt;br /&gt;
  public static void main(String[] a) throws Exception {&lt;br /&gt;
    EmployeeServiceRemote service = null;&lt;br /&gt;
    // Context compEnv = (Context) new InitialContext().lookup(&amp;quot;java:comp/env&amp;quot;);&lt;br /&gt;
    // service = (HelloService)new InitialContext().lookup(&amp;quot;java:comp/env/ejb/HelloService&amp;quot;);&lt;br /&gt;
    service = (EmployeeServiceRemote) new InitialContext().lookup(&amp;quot;EmployeeService/remote&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
    &lt;br /&gt;
    service.doAction();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>