How to run a background process in a J2EE App ?

Hi guys,
Here is the requirement which totally stumped me.
" The web app should have a feature like a background process or something like cron jobs.. which keeps on running in the background and at a particular time each day calls a method". User intervention is not an option.
Now had this been a stand alone app .. I could have done this using Threads.. but i cant possibly use threads in a J2EE app. Any pointers.. how I can go about realizing this
Thanks for your replies.
Cheers!

You could take the approach that SoulTech mentioned and spawn a new thread from the Servlet's init method. To have the servlet invoke this method with no intervention, you would need to set the following parameter in your servlet definition in your web.xml:
<servlet>
  <servlet-name>MyStartupServlet</servlet-name>
  <servlet-class>com.my.company.MyStartupServlet</servlet-class>
  *<load-on-startup>1</load-on-startup>*
</servlet>When you deploy your application, the servlet will be loaded, and its init method will be called.
If your application is running in a servlet container, I believe you are allowed (by the specification) to spawn your own threads, but you should do so carefully. Since you're writing a scheduler and not some kind of worker threads that are messing with your database, I think you should be okay. Still, just to keep it clean you should add any clean-up logic you may need to your servlet's destroy method. I know that in an EJB container, spawning your own threads can definitely be a problem and the container makes no guarantees that they will function correctly. The J2SE Timer class could be used if you're not using EJB, but the Timer class doesn't have support for J2EE - that's at least part of what led to the introduction of the timer beans in J2EE 1.4. If you're already using EJB, especially EJB 3.0, then the timer service provides a convenient built-in mechanism to do exactly what you want.
There are always multiple ways to solve any problem...
Edited by: proflux on May 15, 2008 1:04 PM

Similar Messages

  • How do I run a background process which is under WLE control

    Hello folks:
    How can I run a background process that runs under WLE's control.
    What I am looking for is a way to have a process that runs in an
    infinite loop and polls the database to see if there is any background
    work that needs to be done. But I still want the process to be managed
    by WLE for fault tolerance.
    Thanks,
    Ram Ramesh
    [email protected]

    The easiest way to do this is to write a Tuxedo server (i.e., using only
    ATMI and no CORBA stuff) that does the following:
    1.) In tpsvrinit(), the last thing that it should do is a tpacall to the
    service contained in this server (and nowhere else) with the TPNOREPLY
    flag.
    2.) In the method that implements the service, do your database work, sleep
    for a little while, do another tpacall to itself with the TPNOREPLY flag,
    and return.
    Hope this helps,
    Robert
    Ram Ramesh wrote:
    Hello folks:
    How can I run a background process that runs under WLE's control.
    What I am looking for is a way to have a process that runs in an
    infinite loop and polls the database to see if there is any background
    work that needs to be done. But I still want the process to be managed
    by WLE for fault tolerance.
    Thanks,
    Ram Ramesh
    [email protected]

  • Photoshop CS6 still running in Background Processes, won't close

    Lately, I've been having a problem with Photoshop CS6 where, even after I close the program, Photoshop.exe is still running under Background Processes in the task manager. Hitting "end task" on the program doesn't do anything. It takes up quite a big portion of my processing power, and it usually closes on its own if I just wait a good 5-10 minutes. Even weirder, while this "Ghost Photoshop" is running in the background, I can launch a new version of Photoshop, that will run at the same time without any trouble (aside from the expected slowness when a chunk of my processing power is being eaten up by whatever Ghost Photoshop is doing). I'm running Photoshop CS6 on Windows 8, with just one extension installed-- Coolorus 2.0.

    They were using the little red "x", file > quit allowed her to reopen the program etc. I find it weird that it wont close with the "x" but if I right click the icon on the task bar, it wont allow me to reopen or do anything with it so I was under the assumption it was stuck open.

  • When MRP run through background process in MDBT open PR and PO not comming?

    Hi,
    When MRP run through backgroung process in MDBT open PR and PO not coming in MDBT result.
    Pls advise accordingaly.
    Regards
    rk

    Ram,
    Either I am totally misunderstanding your statements, or your business people are misinformed.  
    The output of MD01 (MRP total run in foreground) and the output of MDBT (MRP total Run in Background) ARE IDENTICAL, provided you have selected the same parameters.  
    Neither output contains a discrete listing of open Purchase orders and Purchase requisitions.
    Standard output of both MD01 and MDBT are:
    1.  List of materials processed, with exception messages
    2.  Statistics
    In addition, both of these programs also write MRP records to the MRP databases, provided that the "Display Material List" parameter is set.  In this case, both of these programs will produce data that can be further reviewed and managed in MD05 and MD06. MD06 is the tool that most planners use to process the MRP database info.
    If you wish to see a listing of the entire MRP results (either MD01 or MDBT), then execute transaction MDLD.  This will produce either a spoolfile or a printed document.
    For the PO or PR listings, review my earlier suggestions.
    Rgds,
    DB49

  • Java code running as background process in Linux causes high CPU util.

    I'm running a piece of java code as a background process in Redhat 7.1 . When I specify to run it as a background process (using the '&') at the command line, I get CPU utilization at around 5% and it dips.
    When I edit the script that runs the java code to specify running it as a background process withint the script itself (java ..... &) and then go to the command line and run the script, the CPU utilization shoots up to 95% and stays at the low 90's - very high 80's range for the CPU utilization..
    I'm hoping someone has any idea for this behavior and a way to fix it.
    Thanks in advance,
    Sarat..

    This is an interesting post and i'm sory i don't have time to
    experament before i answer
    you could of course run the script as background
    *.sh &
    but that's probubly not what you want
    I think the solution lies in giving the
    proccess a job number %n
    then setting it %n &
    it might even work to
    put something like %java &
    Anyway when it's running fullout
    it is because it is in the
    current terminal process group PID.
    wish i could help more

  • How to run the application process

    Dear all,
    I create an application on demand and when I called it it seems to return nothing.
    How I can run only the process ?
    Thanks
    Eric

    Hi,
    It seems you want to do onClick or onmauseover event as I see your javascript function. As I did something like you probobly want to do, Yuo have to first declare javascript file into static files (shared component) then you need to declare onclick/onmauseover event somewhere on the page ( link in the report or something ...) and finally you have to build process on demond to show what you want to see after onclick/onmauseover event.
    This is what i did and it works fine.

  • How to run a BPEL process once every morning?

    Hi All!
    I am working on a BPEL process which will send email greetings to one/group depending on the day it is, like birthday/national festivals etc. I want this process to run by itself every morning once,and do the work.
    But I don't know how to make the process run once every morning? Please let me know how to schedule a BPEL process to run every 24 hours.
    Thanking in advance.
    Regards,
    Deepika.

    Some other links on scheduling and bpel :
    http://technology.amis.nl/blog/?p=1372
    http://clemensblog.blogspot.com/2006/04/bpel-scheduling-reoccuring-processes.html
    Running BPEL service as a scheduled process...

  • ATP Re-Run in background processing for sales order

    Hello All,
    In sales order i need to re run the ATP check for the quantity confirmation in background processing.
    Scenario is :
    I have created orders with order quantity 100.
    while creating the order stock for the same material was only 20 so ultimately it will not confirmed the quantity.
    After the some period i m increasing stock of same material by 120. Now, same order which i created before can be confirmed as i need only 100 quantity in that. but for the same I need to manually run the ATP again and then it will confirm the quantity.
    instead of manually re run the ATP again i want to do this activity in background processing so that it will automatically confirmed the stock once inventory increased.
    Is there any provision in sap to avoid this manual task with the help of background processing or any program?
    Thanks and Regards,
    Rasik

    Hi,
    This can be achieved by rescheduling the orders .
    << Moderator message - Cut and paste response from http://help.sap.com/saphelp_470/helpdata/en/93/744c0c546011d1a7020000e829fd11/content.htm removed and points unassigned. Plagiarism is not allowed in SCN >>
    You reach the Sales screen.
    Select Environment ® Backorders ® Rescheduling ® Execute.
    You can  also simulate the backorders for rescheduling before confirming by selecting the simulateevaluate option.
    Prerequisite for rescheduling the line items of the order is that at schedule line you should not flag the  field fixed date and quantity field. Also for ATP you must have defined the scope of check with checking rule BO(i guess) for that particular plant in combination of checking group .
    Hope this will help you.
    Thanks and Regards,
    Atulkumar Dagade
    Edited by: Rob Burbank on Jan 24, 2012 10:16 AM

  • How to examine Oracle background process (SMON, PMON, DBW0, ...) on WIN OS

    Dear All :
    In Linux/Unix OS , we can check Oracle background process with command
    ps -ef | grep ora
    ,but how to check on Windows OS ? Can anyone show me how to do that...
    thanks alot ~
    with regards

    set line 400
    select
    A.SID,
    A.SERIAL#,
    A.PROGRAM,
    P.PID,
    P.SPID,
    A.OSUSER, /* Who Started INSTANCE */
    A.TERMINAL,
    A.MACHINE,
    A.LOGON_TIME,
    B.NAME,
    B.Description
    ,P.PGA_USED_MEM
    ,P.PGA_FREEABLE_MEM
    ,P.PGA_MAX_MEM
    from
    v$session A,
    v$process P,
    v$bgprocess B
    where
    A.PADDR=B.PADDR
    AND A.PADDR=P.ADDR
    --and   A.type='BACKGROUND'
    --Alternative (you can use BACKGROUND column from v$process )
    AND P.BACKGROUND=1
    HTH
    Girish Sharma

  • How to run long background jobs in ADF applications

    Hi,
    I'm looking for some guidance on how to run an asynchronous job within an ADF application with proper progress notification in the current page.
    Let's assume we have some long running task (e.g. generating notification emails from a bunch of rows in my view object and send them) with the corresponding classes implemented in the DataModel as part of the business logic (e.g. a class that sends a mail to a given recipient).
    Let's assume all the relevant methods can be exposed in the appmodule's client interface so they can be invoked from the ViewController if needed.
    In my jspx page I have implemented the standard af:poll+af:progressIndicator mechanism to give feedback about the running task, backed by a custom BoundedRangeModel
    with methods getValue() and getMaximum(). This works.
    However, all the examples I've found on the net are very very simplistic and only deal with simple counters or countdowns.
    But how to actually implement the whole mechanism in a real life scenario? How do I run the job itself and make it give feedback to my BoundedRangeModel class
    (which in turn is used by the progressIndicator on the page)?
    Is there a recommended way to do this within ADF apps? I've tried to search something about asynchronous method execution in ADF but there seems to be nothing out there.
    Do I need to use standard Java techniques such as a separate Thread running a Runnable worker? Should I use an observer/observable pattern to notify BoundedRangeModel
    and update its internal variables (current value and maximum)? Would this work across a Datacontrol interface?
    Is anything of this allowed within the ADF framework or I'm just gonna break the whole framework model because do-it-yourself concurrent programming isn't allowed in a multithreaded pooled environment?
    Some explanation about the current recommended best practices and/or some practical examples or articles about that would be great.
    (BTW: I'm using version 11.1.1.2.0 and yes, I've checked the contextual events thing too, but that's just an inter-page communication mechanism so it has has nothing to do with what I need to do.)

    Hi
    I have implement a "Runner" class to generate a pdf to every customer of a mailmerge file, which was uploaded. Its simply easy to do something like this. Just add a button, bound the button with a methode out of you applicationModule and start your implementing Thread in this methode.
    public class Runner implements Runnable {
        private String docFileName;
        private String csvFileName;
        private byte[] csvData;
        private byte[] docData;
        private FtpClient client;
        private String category;
        public Runner(String category, String docFileName, byte[] docData,
                      String csvFileName, byte[] csvData, FtpClient client) {
            this.category = category;
            this.docFileName = docFileName;
            this.docData = docData;
            this.csvFileName = csvFileName;
            this.csvData = csvData;
            this.client = client;
        public void run() {
    }In your applicationModule, you can start your Runner like this:
            Runner runner =
                new Runner(category, docFileName, docData, csvFileName, csvData, client);
            new Thread(runner).start();And to the problem with your progressBar. I would create a managedBean with a HashMap<String, HashMap<String, String>>. Every thread you start, add a HashMap<String, String> to this hashmap with the id of the username/session/whatever (must be bound to the user, which starts the thread). This added HashMap<String, String> should be used by your thread to put some status-information into. Now you can try to bind this info to your progressBar.
    I dont know if this will work, it is just an idea ;-)
    Regards
    Majo

  • How to run a BPEL process in jdeveloper tool instead of BPEL process manage

    is there a way to run the bPEL process in jdeveloper itself ?

    Not really, Oracle introduced test seuite in 10.1.3.3 which allows you to test without calling the endpoints. Probably not really what you are after but may be helpful down the track.
    http://download-uk.oracle.com/docs/cd/B31017_01/integrate.1013/b28981/testsuite.htm
    cheers
    James

  • How to read weblogic user/password within a J2EE app ?

    All,
         There is an J2EE that exposes a webservice and the service can not be secured with ws-security since the service is an exact implementation of an standard that does not mandate  ws-secutiry and only insists on SSL/TLS. The application however needs a legitimate authenticated weblogic user for the rest of its work and hence the app has to read a known user created in the weblogic and then read its password as well and authenticate  within the app and use that authenticated subject. User can create this predefined user in weblogic and we may ask user to store the same weblogic password also in a CSF like OPSS and then have the app read the CSF, but since the password is available in the weblogic internal ldap, we want to leverage that and read the user's password using any of the weblogic mbean's APIs. Can anyone provide a pointer on how to read a user's password within the Weblogic's embedded ldap ?
         We referred to this Developing with the User and Role API - 11g Release 1 (11.1.1) & 6 Managing Security Realms with JMX but could not successfully get it working with J2EE app (Servlet/Filter).

    You can use JMX
    Please find a sample here
    List Users and Groups in Weblogic using JMX | Middleware wonders!!

  • How to run a JRockit process in the background(Linux ia64)

    Hello,
    I am trying to start a JRockit process 1.4.2 (with a Java app) from an SSH console and make it keep running after I log out. This is on Redhat Enterprise Linux WS 4 with Itanium II processor (ia64).
    The obvious thing such as
    java <options> <class> &
    or even
    nohup java <options> <class> &
    Do not work and the process terminates when I log out.
    Is there a recommended method or a facility to run JRockit in the background as a service/daemon? Does JRockit has switch similar to –Xrs of Sun’s JVM?
    Starting the process on system boot and having to reboot the system to restart it are not acceptable.
    Any help will be greatly appreciated.
    Thanks,
    Zapta

    Zapta did get an answer. You may have missed it if you're using nntp to access the forums, since many newsreaders don't track threads that change the subject. I recommende the using the web UI at dev2dev.bea.com.
    Anyway - Use "-Xnohup" with older versions of JRockit. In recent JRockit versions, "-Xrs" works as well, since we seen problems with people hardcoding that flag into various applications launchers (Tomcat for one).
    Cheers!

  • Running a background process

    Hi,
    I have a retail website, and I am tweaking the final
    processing page to make it run faster. Right now, our customers
    wait up to 10 seconds after they hit the confirm button before they
    see the 'transaction complete' page.
    My idea is to take out some of the less important processing
    and run them after the 'transaction complete' page is displayed to
    customers.
    I am on a shared CF7 hosting with cfschedule disabled. Is
    there an alternative way to tell CF to run a script in the
    background?
    Thanks,
    Min

    One of the things I like about jQuery (I know this library
    the best but imagine others work in a similar fashion) is that when
    you submit a form via a jQuery function, jQuery uses the action
    attribute of the form tag to determine where it submits *unless* a
    submit to url is provided in the options object passed into the
    ajaxForm function.
    I haven't tried it before but you should be able to set the
    form action attribute to one url, which would be used if JS is off,
    and set another action url in options object that gets passed into
    the ajax form function
    Here's a sample of setting up an HTML form to submit via
    jQuery (the HTML form would use an alternate action page).
    $(document).ready
    function()
    var options = {
    target: '#formOutput', // target element(s) to be updated
    with server response
    beforeSubmit: showFormRequest, // pre-submit callback
    success: showFormResponse, // post-submit callback
    resetForm: true,
    // other available options:
    url: 'htp://domain.com/blah/blah/blah.cfm', // override for
    form's 'action' attribute
    type: 'post', // 'get' or 'post', override for form's
    'method' attribute
    dataType: 'json' // 'xml', 'script', or 'json' (expected
    server response type)
    //clearForm: true // clear all form fields after successful
    submit
    //resetForm: true // reset the form after successful submit
    // $.ajax options can be used here too, for example:
    //timeout: 3000
    // bind form using 'ajaxForm'
    $('#myform').ajaxForm(options);
    Might not be worth the effort of fit into your requirements
    but wanted to put it out there for you. I have a jQuery-driven CMS
    I built for a client that I could pull some code samples out for
    you if that might help.
    Cheers,
    Craig

  • How to run a background job with the cloud_scheduler package

    Hi,
    Is the cloud_scheduler package able to run background jobs as documented? When you try to run a job in another session using:
    cloud_scheduler.run_job(job_name=>'MYJOB', use_current_session=>false);
    The call fails with:
    ORA-20002: Cannot run job MYJOB. Adhoc background execution is disallowed. Please enable the job instead.
    If you try to use cloud_scheduler.enable to run the job then the job does not run when scheduled.
    Rod West

    Hi Rod,
    Yes, I believe so. Here's a test case that I just ran successfully from SQL Workshop in my database trial service:
    create table myjob_test (aa timestamp with time zone);
    begin
        cloud_scheduler.create_job (
            job_name        => 'MYJOB',
            job_type        => 'PLSQL_BLOCK',
            job_action      => 'begin insert into myjob_test values (systimestamp); commit; end;',
            repeat_interval => 'freq=minutely; interval=3' );
    end;
    begin
        cloud_scheduler.enable ( name => 'MYJOB' );
    end;
    select job_name, state, run_count, failure_count, last_start_date, next_run_date, systimestamp from sys.user_scheduler_jobs;
    select * from myjob_test order by aa;Is the next_run_date in the past for your job? If it is, try disabling/enabling the job to "reinitialize" the job's schedule.
    -- Vlad

Maybe you are looking for