Wicket Multi-Threading with access to the session
Hi We have a complex application which needs to calculate some very expensive things. Those could easily be parallelized so we thought about having a thread pool to do that. Unfortunately, that code needs access to the localizer and the application (for some configuration values) so we're setting the Session and the Application explicitly in that thread using Application.set() and Session.set(). But this always leads to a strange error - I suspect it has something to do with the 'duplicated' session or application? Any hints about how to do this correctly? Do we need to do something special with the session or application at the end of the thread? Thanks! Matt Here's the stacktrace: WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception Root cause: ExceptionConverter: java.io.IOException: No message found for the.document.has.no.pages Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) smime.p7s Description: S/MIME Cryptographic Signature
Re: Wicket Multi-Threading with access to the session
Why not just collect the information you need and pass it to the thread? Can't you know in advance which localized values you are going to need? Best, Ernesto On Wed, Feb 10, 2010 at 12:08 PM, Matthias Keller matthias.kel...@ergon.chwrote: Hi We have a complex application which needs to calculate some very expensive things. Those could easily be parallelized so we thought about having a thread pool to do that. Unfortunately, that code needs access to the localizer and the application (for some configuration values) so we're setting the Session and the Application explicitly in that thread using Application.set() and Session.set(). But this always leads to a strange error - I suspect it has something to do with the 'duplicated' session or application? Any hints about how to do this correctly? Do we need to do something special with the session or application at the end of the thread? Thanks! Matt Here's the stacktrace: WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception Root cause: ExceptionConverter: java.io.IOException: No message found for the.document.has.no.pages Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355)
Re: Wicket Multi-Threading with access to the session
Hi Ernesto Thanks for your reply. This would basically be possible but very complicated because the threads need dozens to hundreds of values, so it would be a very tedious and complicated task to collect everything in advance just to pass it to those threads. Matt On 2010-02-10 12:18, Ernesto Reinaldo Barreiro wrote: Why not just collect the information you need and pass it to the thread? Can't you know in advance which localized values you are going to need? Best, Ernesto On Wed, Feb 10, 2010 at 12:08 PM, Matthias Keller matthias.kel...@ergon.chwrote: Hi We have a complex application which needs to calculate some very expensive things. Those could easily be parallelized so we thought about having a thread pool to do that. Unfortunately, that code needs access to the localizer and the application (for some configuration values) so we're setting the Session and the Application explicitly in that thread using Application.set() and Session.set(). But this always leads to a strange error - I suspect it has something to do with the 'duplicated' session or application? Any hints about how to do this correctly? Do we need to do something special with the session or application at the end of the thread? Thanks! Matt Here's the stacktrace: WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception Root cause: ExceptionConverter: java.io.IOException: No message found for the.document.has.no.pages Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) -- matthias.kel...@ergon.ch +41 44 268 83 98 Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich http://www.ergon.ch __ e r g o nsmart people - smart software smime.p7s Description: S/MIME Cryptographic Signature
Re: Wicket Multi-Threading with access to the session
About share your application IStringResourceLoader objects with your thread ? On Wed, Feb 10, 2010 at 9:25 AM, Matthias Keller matthias.kel...@ergon.chwrote: Hi Ernesto Thanks for your reply. This would basically be possible but very complicated because the threads need dozens to hundreds of values, so it would be a very tedious and complicated task to collect everything in advance just to pass it to those threads. Matt On 2010-02-10 12:18, Ernesto Reinaldo Barreiro wrote: Why not just collect the information you need and pass it to the thread? Can't you know in advance which localized values you are going to need? Best, Ernesto On Wed, Feb 10, 2010 at 12:08 PM, Matthias Keller matthias.kel...@ergon.chwrote: Hi We have a complex application which needs to calculate some very expensive things. Those could easily be parallelized so we thought about having a thread pool to do that. Unfortunately, that code needs access to the localizer and the application (for some configuration values) so we're setting the Session and the Application explicitly in that thread using Application.set() and Session.set(). But this always leads to a strange error - I suspect it has something to do with the 'duplicated' session or application? Any hints about how to do this correctly? Do we need to do something special with the session or application at the end of the thread? Thanks! Matt Here's the stacktrace: WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception Root cause: ExceptionConverter: java.io.IOException: No message found for the.document.has.no.pages Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) -- matthias.kel...@ergon.ch +41 44 268 83 98 Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich http://www.ergon.ch __ e r g o nsmart people - smart software -- Pedro Henrique Oliveira dos Santos
Re: Wicket Multi-Threading with access to the session
I guess you could safely share your IStringResourceLoaders, as they are already shared between multiple session (and thus potentially multiple threads). If you really need to share the Session object between threads, you have to roll some kind of locking. What I've done in the past is adding a ReentrantLock to the session, which every thread has to acquire before using the session. For web request threads, this can be done in WebRequestCycle. However, I would advise against sharing the whole session, but just to share what's actually needed and guard the access to that. cheers, Jonas On Wed, Feb 10, 2010 at 12:08 PM, Matthias Keller matthias.kel...@ergon.ch wrote: Hi We have a complex application which needs to calculate some very expensive things. Those could easily be parallelized so we thought about having a thread pool to do that. Unfortunately, that code needs access to the localizer and the application (for some configuration values) so we're setting the Session and the Application explicitly in that thread using Application.set() and Session.set(). But this always leads to a strange error - I suspect it has something to do with the 'duplicated' session or application? Any hints about how to do this correctly? Do we need to do something special with the session or application at the end of the thread? Thanks! Matt Here's the stacktrace: WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception Root cause: ExceptionConverter: java.io.IOException: No message found for the.document.has.no.pages Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket Multi-Threading with access to the session
pass the application, locale/style/variation into your thread and use application.getlocalizer() to do the localization. -igor On Wed, Feb 10, 2010 at 3:08 AM, Matthias Keller matthias.kel...@ergon.ch wrote: Hi We have a complex application which needs to calculate some very expensive things. Those could easily be parallelized so we thought about having a thread pool to do that. Unfortunately, that code needs access to the localizer and the application (for some configuration values) so we're setting the Session and the Application explicitly in that thread using Application.set() and Session.set(). But this always leads to a strange error - I suspect it has something to do with the 'duplicated' session or application? Any hints about how to do this correctly? Do we need to do something special with the session or application at the end of the thread? Thanks! Matt Here's the stacktrace: WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception Root cause: ExceptionConverter: java.io.IOException: No message found for the.document.has.no.pages Complete stack: org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = SignupForm]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1175) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353) at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355) - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org