Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2009, 05:11 PM
Member
 
Join Date: Jun 2009
Posts: 2
Rep Power: 0
joydev is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 06-30-2009, 06:56 PM
OrangeDog's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 838
Rep Power: 2
OrangeDog is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-01-2009, 08:07 AM
Member
 
Join Date: Jun 2009
Posts: 2
Rep Power: 0
joydev is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-03-2009, 05:19 AM
Steve11235's Avatar
Senior Member
 
Join Date: Dec 2008
Posts: 972
Rep Power: 2
Steve11235 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java jobs ManojK Jobs Discussion 4 07-01-2009 05:11 AM
Jobs ruchadxt Java Announcements 0 01-22-2009 11:21 AM
Java Jobs With GC sponsorship TX recruitness Jobs Offered 0 12-19-2008 11:36 PM
Jobs kiko091286 Jobs Offered 1 08-15-2008 02:41 AM
html jobs abcdefg Jobs Wanted 2 04-21-2008 06:29 PM


All times are GMT +2. The time now is 03:46 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org