You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Henrique Boregio <hb...@gmail.com> on 2011/05/03 22:07:02 UTC

Initializing new thread in WicketApplication.init()

Hi, I have a very simple thread that sleeps most of the time. Every
hour, it goes to the database to check what new stuff has been added,
and generates a summary of that.

This thread is started in my WicketApplication.init() method.

The problem is that the run() method of this thread, needs access to
the following method
"WebApplication.get().getServletContext().getContextPath()" but when
it tries to access this method, the following error occurs:

org.apache.wicket.WicketRuntimeException: There is no application
attached to current thread Thread

Any suggestions? Many thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Initializing new thread in WicketApplication.init()

Posted by Henrique Boregio <hb...@gmail.com>.
Actually..no, I hadn't thought about that.
Read up on how to kill threads and just finished implementing it. Thanks!



Also be sure to kill your thread in the application's onDestroy() otherwise
old threads will hang around if you do redeploys, but don't bounce the JVM.

You probably already thought of that. My scars are still fresh...

-Clint

On Tue, May 3, 2011 at 3:37 PM, Henrique Boregio <hb...@gmail.com> wrote:

Thanks Martin...had to do some refactoring but your solution worked great.

On Tue, May 3, 2011 at 5:07 PM, Henrique Boregio <hb...@gmail.com>
wrote:
Hi, I have a very simple thread that sleeps most of the time. Every
hour, it goes to the database to check what new stuff has been added,
and generates a summary of that.

This thread is started in my WicketApplication.init() method.

The problem is that the run() method of this thread, needs access to
the following method
"WebApplication.get().getServletContext().getContextPath()" but when
it tries to access this method, the following error occurs:

org.apache.wicket.WicketRuntimeException: There is no application
attached to current thread Thread

Any suggestions? Many thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: user...@wicket.apache.org
For additional commands, e-mail: user...@wicket.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Initializing new thread in WicketApplication.init()

Posted by Clint Checketts <ch...@gmail.com>.
Also be sure to kill your thread in the application's onDestroy() otherwise
old threads will hang around if you do redeploys, but don't bounce the JVM.

You probably already thought of that. My scars are still fresh...

-Clint


On Tue, May 3, 2011 at 3:37 PM, Henrique Boregio <hb...@gmail.com> wrote:

> Thanks Martin...had to do some refactoring but your solution worked great.
>
> On Tue, May 3, 2011 at 5:07 PM, Henrique Boregio <hb...@gmail.com>
> wrote:
> > Hi, I have a very simple thread that sleeps most of the time. Every
> > hour, it goes to the database to check what new stuff has been added,
> > and generates a summary of that.
> >
> > This thread is started in my WicketApplication.init() method.
> >
> > The problem is that the run() method of this thread, needs access to
> > the following method
> > "WebApplication.get().getServletContext().getContextPath()" but when
> > it tries to access this method, the following error occurs:
> >
> > org.apache.wicket.WicketRuntimeException: There is no application
> > attached to current thread Thread
> >
> > Any suggestions? Many thanks!
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Initializing new thread in WicketApplication.init()

Posted by Henrique Boregio <hb...@gmail.com>.
Thanks Martin...had to do some refactoring but your solution worked great.

On Tue, May 3, 2011 at 5:07 PM, Henrique Boregio <hb...@gmail.com> wrote:
> Hi, I have a very simple thread that sleeps most of the time. Every
> hour, it goes to the database to check what new stuff has been added,
> and generates a summary of that.
>
> This thread is started in my WicketApplication.init() method.
>
> The problem is that the run() method of this thread, needs access to
> the following method
> "WebApplication.get().getServletContext().getContextPath()" but when
> it tries to access this method, the following error occurs:
>
> org.apache.wicket.WicketRuntimeException: There is no application
> attached to current thread Thread
>
> Any suggestions? Many thanks!
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Initializing new thread in WicketApplication.init()

Posted by Martin Grigorov <mg...@apache.org>.
While creating the thread pass the value of
getServletContext().getContextPath() as constructor parameter.
It wont change later during the app lifetime.

On Tue, May 3, 2011 at 10:07 PM, Henrique Boregio <hb...@gmail.com> wrote:
> Hi, I have a very simple thread that sleeps most of the time. Every
> hour, it goes to the database to check what new stuff has been added,
> and generates a summary of that.
>
> This thread is started in my WicketApplication.init() method.
>
> The problem is that the run() method of this thread, needs access to
> the following method
> "WebApplication.get().getServletContext().getContextPath()" but when
> it tries to access this method, the following error occurs:
>
> org.apache.wicket.WicketRuntimeException: There is no application
> attached to current thread Thread
>
> Any suggestions? Many thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org