  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Struts - A MVC web framework | | Tomcat - JSP/Servlet container | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | | JSP - A mailing list about Java Server Pages specification and reference | |
Struts & Hibernate
|
|
|
  | | | where to put the schedular | where to put the schedular 2003-08-06 - By Pradeep Kumar
Back Sean, thanks for your comments.
One question I have here: Is timer service specific to EJB? I might not even use EJBs and use something like Hibernate. Given this, I am wondering if common application level services like Timer, are part of Servlets 2.3 or JSP 2.0
Also does anyone know when we could see the Final release of J2EE 1.4 reference implementation.
Thanks. Pradeep -- --Original Message-- -- From: Sean Brydon [mailto:Sean.Brydon@(protected)] Sent: Wednesday, August 06, 2003 1:09 AM To: J2EEPATTERNS-INTEREST@(protected) Subject: Re: where to put the schedular
Hi, regarding your question about J2EE 1.4 > Does anyone have more info on the Adaption of 1.4?! You are correct that J2EE1.4 will have a J2EE timer service in the EJB container and a Timer Bean which can receive notifications from the timer service. I aggree that it will be a very nice standard feature for J2EE. J2EE1.4 is not FCS yet(specifications had to iron out some WSI support) so is not finalized, so there are no complete 1.4 app servers available yet, but they are coming soon. The J2EE 1.4 beta2 RI app server is available now for download if you want to try a 1.4 app server at http://java.sun.com/j2ee It has the J2EE 1.4 timer bean support as well as web service support if you want to try some of the standard 1.4 features.
Below is a snippet from an Entity Bean used in the BluePrints Adventure Builder new early access 3.1 release that shows usage of the timer service. It will give you some idea of the usage.
import javax.ejb.*; import javax.ejb.Timer ; import java.util.*; import com.sun.j2ee.blueprints.servicelocator.ejb.*;
public abstract class ManagerBean implements EntityBean, TimedObject { private static final String TIMER_INTERVAL_ENV_NAME "java:comp/env/param /opc/OrderTrackingTimerInterval"; private EntityContext context = null;
// CMP fields public abstract String getOrderId(); public abstract void setOrderId(String orderId);
public abstract String getStatus(); public abstract void setStatus(String status);
// EJB create methods public String ejbCreate(String orderId, String status) throws CreateException { ...set fields }
public void ejbPostCreate(String orderId, String status) throws CreateException { try{ ServiceLocator sl = new ServiceLocator(); //get the timer interval in minutes and convert to milliseconds long intervalDuration (Long.parseLong(sl.getString(TIMER_INTERVAL_ENV _NAME))) * 60000; //timer starts after this duration in milliseconds long initialDuration = 60000; TimerService timerService = context.getTimerService(); Timer timer = timerService.createTimer(initialDuration, intervalDuration, null); } catch(NumberFormatException ne){ throw new CreateException("Exception creating timer ! " + ne.getMessage()); } }
//method called by the contatiner when the timer goes off public void ejbTimeout(Timer timer) { updateOrderStatus(); }
//method to update order status private void updateOrderStatus(){ String stat = getStatus(); if (stat.equalsIgnoreCase("PENDING")) { setStatus("APPROVED"); } if (stat.equalsIgnoreCase("APPROVED")) { setStatus("SHIPPED_PART"); } if (stat.equalsIgnoreCase("SHIPPED_PART")) { setStatus("COMPLETED"); cancelTimer(); } }
//method to cancel timers private void cancelTimer(){ TimerService timerService = context.getTimerService(); Iterator iter = timerService.getTimers().iterator(); if(iter.hasNext()){ Timer timer = (Timer) iter.next(); timer.cancel(); } }
hope that helps, Sean Stefan Frank wrote:
> Is this really such a good Idea?! The Timer starts a separate Thread for > Scheduling - and this will interfere with the Thread-Pooling Mechanisms > of most common App-Servers (Starting Threads in a Container was once > considered a no-no in j2ee: If I remember it right, then there are > mechanisms in the new JCA that allow you to request a thread from the > AppServer.) Almost every vendor formerly had some proprietary extensions > to perform at least basic Scheduling from inside the app-server - this > has finally resulted in the introduction of a TimerService( > http://www.theserverside.com/resources/article.jsp?l=MonsonHaefel-Column4) > TimerService's can be created at runtime, so reading in a Table and > setting up the Timers is possible. Using a TimerService should save you > from being tied to the Database and also eliminates the need for a > separate Box/process that runs outside your Appserver. But I'm not > completely sure, which server already supports 1.4. Does anyone have > more info on the Adaption of 1.4?! > > cheers > stf > > Rangarajan , Suresh ( Cognizant ) wrote: > >> You can use the java.util.Timer and TimerTask classes for this purpose. >> On startup, you can read the tables and setup the timer. >> >> But, you can not dynamically change the values in the table... >> >> >> -- --Original Message-- -- >> From: Pradeep Kumar [mailto:pradeepk@(protected)] >> Sent: Tuesday, August 05, 2003 6:13 PM >> To: J2EEPATTERNS-INTEREST@(protected) >> Subject: where to put the schedular >> >> >> Hello friends, >> >> This may not be the right forum to ask this question. But I couldn't >> find the >> appropriate forum. >> >> I have requirement, wherein I will have to run 2 types of schedulers. >> I am >> using DB2 8.1 and WebSphere 5 running on windows. >> >> One scheduler, should wake up on a particular date and time defined >> in a >> table and then updates some other tables. >> Another scheduler, should wake up on a particular date and time >> defined in a >> table and then sends out emails. >> >> I think I have 3 options: >> 1. Define and configure the schedulers using the DB2 tools. >> 2. Build custom schedulers in my WebSphere application, that >> periodically checks the system date with scheduled date and then >> updates the >> relevant table and also sends out email using the Java mail APIs >> 3. write a stand alone java program and use a windows scheduler. >> >> These schedulers are purely back-end activities and do not depend on >> the user >> actions. The first option may be the appropriate one, but I am not >> sure about >> the implications. >> >> Your comments are appreciated. >> >> Thanks. >> Pradeep Kumar >> MindTree Consulting >> 91 80 6711777 Xtn: 2033 >> >> >> >> DISCLAIMER: >> This message (including attachment if any) is confidential and may be >> privileged. Before opening attachments please check them for viruses >> and defects. MindTree Consulting Private Limited (MindTree) will not >> be responsible for any viruses or defects or any forwarded >> attachments emanating either from within MindTree or outside. If you >> have received this message by mistake please notify the sender by >> return e-mail and delete this message from your system. Any >> unauthorized use or dissemination of this message in whole or in part >> is strictly prohibited. Please note that e-mails are susceptible to >> change and MindTree shall not be liable for any improper, untimely or >> incomplete transmission. >> >> ===================================================================>> Community Web Site (Core J2EE Patterns Catalog - Online Version): >> http://java.sun.com/blueprints/corej2eepatterns >> Getting Started (Beta Version): >> http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns/ >> Get the book: >> http://www.amazon.com/exec/obidos/ASIN/0130648841/corej2eepatte-20 (See http://tte-20.ora-code.com) >> List Archive: >> http://archives.java.sun.com/archives/j2eepatterns-interest.html >> Unsubscribing: >> email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected) >> >> ===================================================================>> Community Web Site (Core J2EE Patterns Catalog - Online Version): >> http://java.sun.com/blueprints/corej2eepatterns >> Getting Started (Beta Version): >> http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns/ >> Get the book: >> http://www.amazon.com/exec/obidos/ASIN/0130648841/corej2eepatte-20 (See http://tte-20.ora-code.com) >> List Archive: >> http://archives.java.sun.com/archives/j2eepatterns-interest.html >> Unsubscribing: >> email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected) >> >> >> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- >> >> This e-mail and any files transmitted with it are for the sole use of >> the intended recipient(s) and may contain confidential and privileged >> information. >> If you are not the intended recipient, please contact the sender by >> reply e-mail and destroy all copies of the original message. >> Any unauthorised review, use, disclosure, dissemination, forwarding, >> printing or copying of this email or any action taken in reliance on >> this e-mail is strictly >> prohibited and may be unlawful. >> >> Visit us at http://www.cognizant.com >> >> ===================================================================>> Community Web Site (Core J2EE Patterns Catalog - Online Version): >> http://java.sun.com/blueprints/corej2eepatterns >> Getting Started (Beta Version): >> http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns/ >> Get the book: >> http://www.amazon.com/exec/obidos/ASIN/0130648841/corej2eepatte-20 (See http://tte-20.ora-code.com) >> List Archive: >> http://archives.java.sun.com/archives/j2eepatterns-interest.html >> Unsubscribing: >> email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected) > > > ===================================================================> Community Web Site (Core J2EE Patterns Catalog - Online Version): > http://java.sun.com/blueprints/corej2eepatterns > Getting Started (Beta Version): > http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns/ > Get the book: > http://www.amazon.com/exec/obidos/ASIN/0130648841/corej2eepatte-20 (See http://tte-20.ora-code.com) > List Archive: > http://archives.java.sun.com/archives/j2eepatterns-interest.html > Unsubscribing: > email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
===================================================================Community Web Site (Core J2EE Patterns Catalog - Online Version): http://java.sun.com/blueprints/corej2eepatterns Getting Started (Beta Version): http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns/ Get the book: http://www.amazon.com/exec/obidos/ASIN/0130648841/corej2eepatte-20 (See http://tte-20.ora-code.com) List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
DISCLAIMER: This message (including attachment if any) is confidential and may be privileged. Before opening attachments please check them for viruses and defects. MindTree Consulting Private Limited (MindTree) will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside. If you have received this message by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission.
==========================================================================To unsubscribe, send email to listserv@(protected) and include in the body of the message "signoff J2EE-INTEREST". For general help, send email to listserv@(protected) and include in the body of the message "help".
|
|
 |