Results 1 to 4 of 4
  1. #1
    joydev is offline Member
    Join Date
    Jun 2009
    Posts
    2
    Rep Power
    0

    Default Query regarding cancelling long run jobs

    I am Calling a java standalone program through a cronjob.

    In the program I have written logic that will create a CSV file.
    The problem is sometimes it takes long time to create the csv file, so I need to facilitate user some way of cancelling it. User will cancel it through UI.

    Can any body suggest what could be the best approach to implement it.

    Also I want multi threaded approach too because many users will request to create CSV file.

    Thanks

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Structure the job so that it periodically checks a volatile boolean variable to see if it should abort. Alternatively you could use the Thread.interrupted mechanisms. Either way, you need to manually check.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    joydev is offline Member
    Join Date
    Jun 2009
    Posts
    2
    Rep Power
    0

    Default

    Thanks for your reply.

    I have tried the way you suggested by calling Thread.interrupt().
    But the thread continues to run without terminating.

    I read in some other forums we need to return from run() method to abort the thread.
    But in my scenario in the run() method I am calling a function that will do some processing
    to create CSV file

    suppose

    run()
    {
    createCSVFile();
    }

    Once the method createCSVFile is called how it is possible to check for a boolean flag that will return from the run() method. I want to cancel the thread when createCSVFIle() method will be called.

    Please suggest

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    If you want to use a UI, then you need only start the UI on the EDT. As far as interrupting the thread, that only sets the thread's interrupted flag unless the thread is blocking at the time of the interrupt.

    During the CSV build, check the thread's interrupted flag at the end of the loop (there must be at leat one.) In the UI, you can interrupt the main thread. If you don't get an InterruptedException, that will at least set the interrupted flag.

Similar Threads

  1. java jobs
    By ManojK in forum Jobs Discussion
    Replies: 4
    Last Post: 07-01-2009, 05:11 AM
  2. Jobs
    By ruchadxt in forum Java Software
    Replies: 0
    Last Post: 01-22-2009, 11:21 AM
  3. Java Jobs With GC sponsorship TX
    By recruitness in forum Jobs Offered
    Replies: 0
    Last Post: 12-19-2008, 11:36 PM
  4. Jobs
    By kiko091286 in forum Jobs Offered
    Replies: 1
    Last Post: 08-15-2008, 02:41 AM
  5. html jobs
    By abcdefg in forum Jobs Wanted
    Replies: 2
    Last Post: 04-21-2008, 06:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •