no you dont need the threadlocal
WebRequestCycle is already a thread local thats only used for one request
so in your WebRequestCycle you can have a start time. (onBeginRequest)
and then in onEndRequest you do your calculation.

The problem that i see is that that time covers 2 things. 1 the request
phase on the page of the component that is clicked on
and the response page that could be again that same page but could also be a
completely different one.
So at that time you are testing 2 pages

johan



On Jan 31, 2008 1:32 PM, lars vonk <[EMAIL PROTECTED]> wrote:

> Hi thanks for the replies,
>
> Yes I want to do it per Page so I can monitor the performance per page.
>
> Here is how I implemented it, I am not sure if I always get the name
> of the Page name in the implementation of onEndRequest. (Allthough
> during tests I always got the name of the Page.)
>
> public class JAMonMonitoredWebRequestCycle extends WebRequestCycle {
>
>    static final String UNIT = "ms.";
>
>    private ThreadLocal<Long> startTimes = new ThreadLocal<Long>();
>
>    public JAMonMonitoredWebRequestCycle(WebApplication application,
> WebRequest request, Response response) {
>        super(application, request, response);
>    }
>
>    @Override
>    protected void onBeginRequest() {
>        super.onBeginRequest();
>        addStartTimeToThreadLocal();
>    }
>
>    @Override
>    protected void onEndRequest() {
>        super.onEndRequest();
>        calculateDurationAndAddToMonitor();
>    }
>
>
>    private void addStartTimeToThreadLocal() {
>        startTimes.set(System.currentTimeMillis());
>    }
>
>    private void calculateDurationAndAddToMonitor() {
>        if(startTimes.get() != null) {
>            Class<?> pageClass = null;
>            if(getWebResponse().isAjax() && getWebRequest().getPage() !=
> null) {
>                pageClass = getWebRequest().getPage().getClass();
>            } else {
>                pageClass = getResponsePageClass();
>            }
>            if(pageClass != null) {
>                MonitorFactory.add(pageClass.toString(), UNIT,
> System.currentTimeMillis() - startTimes.get().doubleValue());
>            }
>            startTimes.set(null);
>        }
>    }
>
> }
>
>
> I believe the Page to be rendered is not availble yet in the
> onBeginRequest so I use MonitorFactory.add() in the onEndRequest and
> store the startTime in a ThreadLocal. While typing this email I am
> thinking that WebRequestCycle is statefull so I probably do need the
> ThreadLocal right?
>
> Lars
>
> On Jan 30, 2008 8:22 PM, Eelco Hillenius <[EMAIL PROTECTED]>
> wrote:
> > On Jan 30, 2008 11:20 AM, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > > but per page...
> >
> > Why don't you just answer then.
> >
> >
> > Eelco
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to