Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

AsyncContext setTimeout doubt ?

 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the api for setTimeout says :

Sets the timeout (in milliseconds) for this AsyncContext.
The timeout applies to this AsyncContext once the container-initiated dispatch during which one of the ServletRequest#startAsync methods was called has returned to the container.

The timeout will expire if neither the complete() method nor any of the dispatch methods are called. A timeout value of zero or less indicates no timeout.

If setTimeout(long) is not called, then the container's default timeout, which is available via a call to getTimeout(), will apply.

Parameters:
timeout - the timeout in milliseconds
Throws:
IllegalStateException - if this method is called after the container-initiated dispatch, during which one of the ServletRequest#startAsync methods was called, has returned to the container

\


im unable to understand what does container-initiated dispatch means ?

i searched the forum and found this link https://coderanch.com/t/553132/java-Web-Component-SCWCD/certification/AsyncContext-timeout where the discussion regarding the same was going on. please have a look at that discussion. piyush has tried to answer it by saying that container-initiated dispatch means the service() or the doFilter() method but he is not sure. my second question is same what piyush said , how can we get IllegalStateException mentioned in the setTimeOut method above ? please help
Regards
Gurpreet
 
Greenhorn
Posts: 2
Oracle Debian Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About your second question:
void setTimeout(long timeout)
can throw (un-checked) IllegalStateException, when someone is setting a timeout on a AsyncContext object, which already FINISHED its work.

Have a look here:

last line of code should throw an exception

OK, I must admit, my code sample is very primitive, but I'm too lazy to write now multi-class example with async requests running in separate threads
And exactly under such conditions (multi-threaded servlet processing) you have not so bad chance to try working with object, which already finished its work (life-cycle).
I hope, you get the idea: once AsyncContext is recycled you cant use it anymore.
BTW, this is true not only about setTimeout(), but also for nearly all other methods in AsyncContext interface.

And one more hint: just look into the source code of some open-source implementation. I've just done that with "tomcat 7.0"
 
Message for you sir! I think it is a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic