+ All Categories
Home > Documents > JAVA Struts Guide - Execute and Wait

JAVA Struts Guide - Execute and Wait

Date post: 02-Jun-2018
Category:
Upload: apextgi
View: 226 times
Download: 0 times
Share this document with a friend

of 13

Transcript
  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    1/13

    Apex T. G. India Pvt. Ltd

    ExecuteAndWait Interceptor

    Struts Framework

    Introduction

    http://apextgi.in/http://apextgi.in/
  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    2/13

    1

    execAndWait The ExecuteAndWaitInterceptor is used for running long-

    lived actions in the background while showing the user a

    progress meter(loader image using JavaScript) .

    This also prevents the HTTP request from timing out when

    the action takes more than 5 or 10 minutes.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    3/13

    1

    execAndWait Using this interceptor is pretty straight forward.

    Assuming that you are including struts-default.xml, and this

    interceptor is already configured but is not part of any of the

    default stacks then it wont work.

    Because of the nature of this interceptor, it must be

    the last interceptor in the stack.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    4/13

    1

    execAndWait This interceptor works on a per-session basis.

    It means, same action name ( DemoAction.class ) cannot be

    run more than once at a time in a given session. On the

    initial request or any subsequent requests (before the action

    has completed), the wait result will be returned.

    The wait result is responsible for issuing a subsequent

    request back to the action, giving the effect of a self-updating

    progress meter.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    5/13

    1

    execAndWait If no "wait" result is found, Struts will automatically

    generate a wait result on the fly.

    But this result is written in FreeMarker and cannot run

    unless FreeMarker is installed.

    If you don't want to use it with FreeMarker then must

    provide a wait page as a result.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    6/13

    1

    execAndWait Whenever the wait result is returned, the action that is

    currently running in the background will be placed on top of

    the stack.

    This allows you to display progress data, such as a count, in

    the wait page. By making the wait page automatically reload

    the request to the action (which will be short-circuited by

    the interceptor), can give the appearance of an automatic

    progress meter.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    7/13

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    8/13

    1

    execAndWait This interceptor also supports using an initial wait delay. An

    initial delay is a time in milliseconds let the server wait

    before the wait page is shown to the user.

    During the wait this interceptor will wake every 100 milii

    second to check if the background process is done

    premature, thus if the job for some reason doesn't take to

    long the wait page is not shown to the user.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    9/13

    1

    execAndWait This is useful for e.g. search actions that have a wide span of

    execution time. Using a delay time of 2000 millis we ensure

    the user is presented fast search results immediately and for

    the slow results a wait page is used.

    Important: Because the action will be running in a separate

    thread, We can't use ActionContext because it is a

    ThreadLocal.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    10/13

    1

    execAndWait The thread kicked off by this interceptor will be named in

    the form actionNameBackgroundProcess.

    This means if we need to access session data, we need to

    implement SessionAware rather than calling

    ActionContext.getSession().

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    11/13

    1

    execAndWait Parameters:threadPriority (optional) - the priority to

    assign the thread. Default is Thread.NORM_PRIORITY.

    delay (optional) - an initial delay in millis to wait before the

    wait page is shown (returning wait as result code). Default is

    no initial delay.

    delaySleepInterval (optional) - only used with delay. Used

    for waking up at certain intervals to check if the background

    process is already done. Default is 100 millis.

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    12/13

    1

    execAndWait

  • 8/11/2019 JAVA Struts Guide - Execute and Wait

    13/13

    Thanks

    facebook.com/apex.tgi

    twitter.com/ApextgiNoida

    pinterest.com/apextgi

    Stay Connected with us for more chapters on JAVA

    https://www.facebook.com/apex.tgihttps://twitter.com/ApextgiNoidahttp://www.pinterest.com/apextgihttp://www.pinterest.com/apextgihttp://www.pinterest.com/apextgihttps://twitter.com/ApextgiNoidahttps://twitter.com/ApextgiNoidahttps://www.facebook.com/apex.tgi

Recommended