a message bean can be a good idea...
send an XML or text message to your message EJB,
which will process the request in it's own thread...

by the way, for long transactions, if you can avoid transactions
(by default they timeout in 30 seconds. you can change
 that somewhere in the transaction config, but 
 anyway this is costly for the DB)

check the transaction mode used for the EJB...
using NotSupported for is interesting if their is no risk of
incoherence. note that such a non transactional bean 
can call transactional EJB (Required TX mode for example).
each independent method call will be either Commit'ed or Rollback'ed...

If you don't have Message EJB, you can try to add a Thread'able object
in the Servlet context. I did it on Websphere
to scan mail...

then, either use the "load-on-startup" elemnt in web.xml
or explicitly start and stop...

as far as I understand servler context guaranty that
only one instance of the thread is used

you may also look about non HTTP servlet
which may respond to any protocol...
or even to soap clients...

> -----Message d'origine-----
> De: Dirk Storck [mailto:[EMAIL PROTECTED]]
> Date: mercredi 13 février 2002 14:17
> À: Jboss User (E-Mail); Struts User (E-Mail)
> Objet: [JBoss-user] How can I use a background process with JBoss
> 
> 
> Hi,
> 
> I want to do the following:
> 
> I have a ShoppingCart.
> The users clicks on order and the items from the ShoppingCart 
> are moved to
> my OrderBean. ShoppingCart and OrderBean are EJB's.
> 
> Now it comes to the problem. The order must be proccessed in 
> background
> cause it will have a long durration.
> After the order has be proccessed the user should be notived somehow.
> 
> How can I achieve this with JBoss and Struts ? What would be 
> the best way to
> implement this

package fr.cdc.idt.receivemail;

/**
 * Insérez la description du type ici.
 * Date de création : (04/01/02 12:10:45)
 * @author: 
 */
import java.util.Date;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import fr.cdc.idt.sendmail.*;

public class ReceiveMailServlet extends javax.servlet.http.HttpServlet {
/**
 * Free any resources the servlet has acquired
 * that will not be garbage collected.
 */
public void destroy() {
        System.out.println(getClass().getName()+"#destroy()");
        ServletContext cnt=getServletContext();
        Object cobj=cnt.getAttribute("mailPollBean");
                if(cobj!=null){
                  ReceiveMailPollBean
mailPollBean=(ReceiveMailPollBean)cobj;
        System.out.println(getClass().getName()+"#destroy() bean stop");
                  mailPollBean.stop();
        System.out.println(getClass().getName()+"#destroy()
removeattribute");
                  cnt.removeAttribute("mailPollBean");
                }
        super.destroy();
}
/**
 * Process incoming HTTP GET requests 
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {

        performTask(request, response);

}
/**
 * Process incoming HTTP POST requests 
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {

        performTask(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

        return super.getServletInfo();

}
/**
 * Initializes the servlet.
 */
public void init() {
        // insert code to initialize the servlet here

}
/**
* Initializes the servlet.
*/
public void init(ServletConfig cnf) throws ServletException {
    // insert code to initialize the servlet here
    super.init(cnf);

    ServletContext cnt = cnf.getServletContext();

    //String mailhostParm = cfg.getInitParameter("mailhost");

    ReceiveMailPollBean mailPollBean = new ReceiveMailPollBean();
    ReceiveMailBean receiveBean = mailPollBean.getReceiveMailBean();
    receiveBean.setUserName("testportail");
    receiveBean.setPassword("testportail");
    receiveBean.setStoreType("imap");
    receiveBean.setFolderName("INBOX");
    receiveBean.setHostName("tsexchange.idt.cdc.fr");
    AttachmentAdapter attachementListener = new AttachmentAdapter() {
        public void onAttachement(AttachmentEvent event) {
            /* do the job .... */
        }
    };
    receiveBean.addAttachmentListener(attachementListener);
    mailPollBean.setPollingInterval(1000 * 30);

    mailPollBean.start();
    //          Thread.currentThread().sleep(1000*30);
    //        mailPollBean.stop();
    cnt.setAttribute("mailPollBean", mailPollBean);
    /*  ContextObject obj=new ContextObject();
        obj.startTimeStamp();
        
        cnt.setAttribute("obj",obj); */

    System.out.println(getClass().getName() + "#init(servlet conf)");

}
/**
 * Process incoming requests for information
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void performTask(
    javax.servlet.http.HttpServletRequest request,
    javax.servlet.http.HttpServletResponse response) {
    boolean crash = false;
    try {
        // Insert user code from here.
        response.setContentType("text/html");
        /* print ... */
    } catch (Throwable theException) {
        theException.printStackTrace();
    }

}
}

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to