aspose file tools
The moose likes Threads and Synchronization and the fly likes Close Browser window stop thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Close Browser window stop thread" Watch "Close Browser window stop thread" New topic
Author

Close Browser window stop thread

Chinni Bujji
Ranch Hand

Joined: Jan 31, 2007
Posts: 60
Hi

If we close the browser window can we write the code to stop the thread that was running on that page
Any ideas on this how to correlate the user actions

Thanks

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

A thread running on a page?? Are you talking about applets, asynchronous calculations on a server or what?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

If it's an applet (the only case where the thread is actually running in a browser) then closing the browser will terminate the entire JVM. All the threads will end as a result of that. You don't have to write any code to help that process along.
Chinni Bujji
Ranch Hand

Joined: Jan 31, 2007
Posts: 60
I have a thread running in a jsp
I have a button which clicked will start the thread and a stop button to stop the thread

but if the user forgot to click the stop the thread button and if the user closes the browser the thread is still running
so i want to know if there is any mechanism which i can use to capture the user activity and stop the thread

thanks in advance
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12269
    
    1
WHY did you want to start a Thread inside a JSP?

JSP are for presentation - I cant think of any reason to start a Thread in one.

Bill

Java Resources at www.wbrogden.com
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Chinni Bujji wrote:but if the user forgot to click the stop the thread button and if the user closes the browser the thread is still running
so i want to know if there is any mechanism which i can use to capture the user activity and stop the thread


Not really. And you can't capture the "user activity" where the user goes home for the night, leaving the browser still open, either. As William Brogden suggested, you might want to review your design. If letting users create unregulated threads is a problem, then consider not letting them do that.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Close Browser window stop thread
 
Similar Threads
question on html:submit
JavaScript :Capturing the Close Event
Stopping browser window closing
display message when close the brower window
problem regarding servlets+ threads