Timer issue in JAVA and J2EE

W.ZH

Basice idea for timer is for java prgoram u can use the java.util.timer to do that.

In EJB, it has javax.ejb.timer. As to J2EE in web server you have to have sth to start the timer  , you can create a context listener in ur app, then this context listener can start timer when u deploy and run your j2ee app.

Note: The
TimerHandle provides a serializable handle to a specific timer. There is a restriction that states that the
TimerHandle cannot be exposed though a remote interface (including a web service endpoint). The container provider is responsible for implementing this interface.

This means that if an EJB contains a timerhandler emthod, this EJB can not expose as a Webservice. (Because you will get JAXB error.)

and timer is sticky to persistence of container, this means even server crash ro reboot, timer still there.

 Collection timersList = timerService.getTimers ();
 for (Object timer: timersList) {
 if (timer instanceof Timer) {
 log.debug ("Timer still running, kill it : "+timer);
 ((Timer)timer).cancel ();

 }
 }

See here for them:

http://www.javabeat.net/articles/3-ejb-30-timer-services-an-overview-1.html

http://www.lucamingardi.com/EN/java_ee_guides/ejb/create_an_ejb_timer.php

http://java-x.blogspot.com/2007/01/ejb-3-timer-service.html

http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/rejb_timerex.html

http://onjava.com/pub/a/onjava/2004/10/13/j2ee-timers.html

Advertisements

read parameter from backing bean

Read query string from backing bean  from  Hobione blog

http://myhost/mybean?inputId=1111

FacesContext context = FacesContext.getCurrentInstance();

  1. Map<String, String> params = context.getExternalContext().getRequestParameterMap();
  2. String ID = params.get(“inputId”);

 FacesContext context = FacesContext.getCurrentInstance();
 Map<String, String> params = context.getExternalContext().getRequestParameterMap();
 String pID = params.get("packageId");

Now ID should have the value 1111

For ADF in faces-config.xml:

<managed-bean>

<description>Backing bean for tree example. </description>

<managed-bean-name>tree</managed-bean-name>

<managed-bean-class>gov.faa.amc.nas.epf.TreeBean</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

<managed-property>

<property-name>packageId</property-name>

<value>#{param.packageId}</value> <!–JSF injects query string value from request parameter –>

</managed-property>

</managed-bean>

In TreeBean.java, I have a instance variable and getter and setter

view plain
copy to clipboard
print
?

private String packageId;

private String packageId;

Caution: Bean scope has to be request otherwise you get a nasty error like this.

view plain
copy to clipboard
print
?

javax.faces.FacesException: Problem in renderResponse: Unable to create managed

bean tree. The following problems were found:

– The scope of the object referenced by expression #{param.packageId}, request, is shorter than the

referring managed beans (tree) scope of session note

refer to :

http://hobione.wordpress.com/tag/query-string/