• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Long running task in servlet

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to run some background job without blocking user's browser which I started in Thread.

here is my code snippet :

calling from controller :

Now my problem is that thread is not sleeping and it blocks user's browser for ever ...

any help will be appriciated..

Thanks,
Rishi


[BSouther: Added UBB CODE tags]
[ March 05, 2008: Message edited by: Ben Souther ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks as if this code will not terminate until "replaceTaskFinished" is set to true (which supposedly happens in replaceTaskThread). So you haven't really an independent thread here.

Also, if "replaceTaskFinished" is an instance variable, then this code is not thread-safe. Any write access to instance variables needs to be synchronized. But, as pointed out above, the code should not wait for it to become true to begin with.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hardly surprising since (as near as I can tell) you are holding on to the thread that is handling the request that started the whole thing. You should let that request terminate normally with something like a "working" HTML page and find another way to update the user. There have been a lot of discussions of this sort of thing on the ranch so do some searches.

Bill
 
Ris Yagnik
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the replies...

I got what you both are saying ...How about setting ReplaceTask Thread as daemon thread will that work ?

replaceTaskThread.setDaemon(true):
replaceTaskThread.start():

Do you think daemon thread will garbage collected by web container any idea on performance how will it affect ?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On my site, I have a simple demo app that does something similar.
http://simple.souther.us/not-so-simple.html

Look for LongRunningProcess.
It might be enough to get you going in the right direction.
 
Ris Yagnik
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help...It helped a lot

Rishi
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic