cancel
Showing results for 
Search instead for 
Did you mean: 

timerTask run

Former Member
0 Kudos

i deploy my EAR application with EJB and WEB ...

i run a timertask...

timer t1=new timer();

t1.schedule(task,0,180*1000); //every 3 minutes run...

the thread cannot stopped...eventhough i stop the EAR that deploy in the application..or even i change my code take take out the timer...

the timer still active..

wat do you think


public class PoolingOutMailAck implements ServletContextListener {
	/**
	 * 
	 */
	TimerTask t1;
	Timer outMailAckTimer;
	OutMailAckPooling outMailAckPool=new OutMailAckPooling();
	
public PoolingOutMailAck() {
	super();
	// TODO Auto-generated constructor stub
}

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
outMailAckTimer=new Timer();
outMailAckTimer.schedule(outMailAckPool,0,300*1000);
}

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	public void contextDestroyed(ServletContextEvent arg0) {
}

Message was edited by:

yzme yzme

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

yzme,

It's stricly not recommended to use Java threads management in EJB projects. java.uitl.Timer uses threads underneath, so you are violating this restriction and hence getting unpredictable/wrong results. Actually, Timer is designed to be used by client-side Java programs (desktop applications, applets) rather then by server-side ones.

The better option is to use <a href="http://help.sap.com/saphelp_webas630/helpdata/en/6b/2550d23ef1994580114d6064bc44a1/frameset.htm">Timeout Service</a>. Also see excellent post <a href="/people/maksim.rashchynski/blog/2006/08/07/intercomponent-parameters-exchange">Intercomponent parameters exchange</a> by <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=pyouhggpqqi%3d">maksim Rashchynski</a> for advanced example of Timeout Service usage.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net