You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Douglas Ferguson <do...@douglasferguson.us> on 2010/05/28 01:53:10 UTC
using injected services in a child thread
I'm using 1.4.8 (not the ITL version).
I have pass a runnable to an executer, how can I make use of classes that use @Inject?
When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
I've tried these combinations:
1) @Inject into the page and then pass the reference to the constructor of the runnable
2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
Neither works.
D/
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
I'm looking at that URL and I don't see anything in either of those snipets of code that would solve the problem.
Can you explain?
On May 28, 2010, at 3:34 PM, Alex Objelean wrote:
>
> No, it is about Sven Maier's solution: http://pastebin.com/NN58fiZx
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235168.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Alex Objelean <al...@gmail.com>.
No, it is about Sven Maier's solution: http://pastebin.com/NN58fiZx
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235168.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by James Carman <ja...@carmanconsulting.com>.
On Fri, May 28, 2010 at 4:25 PM, Alex Objelean <al...@gmail.com> wrote:
>
> 2) Let the client code to create the Future. Though it is a good approach, I
> don't like the fact that the client is responsible for implementing such
> details each time it overrides the execute() method. It would be cleaner to
> move this logic inside the component..
>
Are you talking about my approach here? If so, it's not a future,
it's a Runnable I'm talking about. And, to run something with an
executor, you have to create a Runnable anyway, so it's not hard to
just let something "wrap" it to provide the functionality. Also, I
guess you could use aspects for this, too.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Alex Objelean <al...@gmail.com>.
There are two proposed solutions:
1) use the beforeExecute()/afterExecute() methods to set/clear the
Application's ThreadLocal variable so that it's available during the
execution of the task.
2) Let the client code to create the Future. Though it is a good approach, I
don't like the fact that the client is responsible for implementing such
details each time it overrides the execute() method. It would be cleaner to
move this logic inside the component..
Alex
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235157.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
What exactly is the "solution"?
I've read the code and it looks like the Application would still not be available in the runner thread.
D/
On May 28, 2010, at 3:00 PM, Alex Objelean wrote:
>
> The link you have found was a workaround to avoid the problem. You can see
> the actual problem in this example:
>
> http://pastebin.com/0GwGXkmr
>
> The usage example:
>
> @SpringBean
> private Service service;
> new ProcessExecutorPanel("associatedFilesMigration") {
> @Override
> protected void execute() {
> //a business logic method which takes a lot time to complete
> //in this context Application is not available and it complains
> that Application is not attached to current thread
> service.startMigration();
> }
> };
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235118.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Alex Objelean <al...@gmail.com>.
The link you have found was a workaround to avoid the problem. You can see
the actual problem in this example:
http://pastebin.com/0GwGXkmr
The usage example:
@SpringBean
private Service service;
new ProcessExecutorPanel("associatedFilesMigration") {
@Override
protected void execute() {
//a business logic method which takes a lot time to complete
//in this context Application is not available and it complains
that Application is not attached to current thread
service.startMigration();
}
};
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235118.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
I found this:
http://pastebin.com/NN58fiZx
But I don't see anything that would tied the Application to the child thread.
It is just a button that would exec a thread for you.
D/
On May 28, 2010, at 1:06 PM, Douglas Ferguson wrote:
> I've been following the thread to some degree, but I missed that.
>
> Is there a code example somewhere?
>
> D/
>
> On May 28, 2010, at 11:34 AM, James Carman wrote:
>
>> Perhaps you would be interested in the other threads that have been
>> going on where we discuss InheritableThreadLocal. In there Jeremy
>> gave a good solution that would fix what you're seeing. Basically,
>> you use the beforeExecute()/afterExecute() methods to set/clear the
>> Application's ThreadLocal variable so that it's available during the
>> execution of the task.
>>
>> On Fri, May 28, 2010 at 12:01 PM, Douglas Ferguson
>> <do...@douglasferguson.us> wrote:
>>> I'm still spinning my wheels on this one.
>>>
>>> Let me try to explain better..
>>>
>>> On the page I have
>>>
>>> @Inject DAOFactory
>>> @Inject MyService
>>>
>>> On the DAOFactory I have
>>>
>>> @Inject DAO1
>>> @Inject DAO2
>>> etc...
>>>
>>> On MyService I have
>>>
>>> @Inject DAO1
>>>
>>> In my module I have
>>>
>>> bind(MyService.class).toInstance(new MyService());
>>> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
>>> bind(DAO1.class).in(Singleton.class);
>>> bind(DAO2.class).in(Singleton.class);
>>>
>>> On the page I also have:
>>>
>>> genericWorkPool.submit(new Runnable() {
>>>
>>> @Override
>>> public void run() {
>>> try {
>>> //Do stuff with DAOFactory -- works
>>> //Do stuff with MyService -- Blow ups <<<---- See exception below
>>> } catch (Throwable t) {
>>> log.error("Error sending email on Signup: " + t.getMessage(), t);
>>> }
>>> }
>>> }
>>>
>>> This is the error I get
>>>
>>> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
>>> at org.apache.wicket.Application.get(Application.java:179)
>>> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
>>> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
>>> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>>>
>>> I can't understand why DAOFactory would work ok but MyService wouldn't.
>>>
>>>
>>> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>>>
>>> I'm using 1.4.8 (not the ITL version).
>>>
>>> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>>>
>>> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>>>
>>> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>>>
>>> I've tried these combinations:
>>>
>>> 1) @Inject into the page and then pass the reference to the constructor of the runnable
>>> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>>>
>>> Neither works.
>>>
>>> D/
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
I've been following the thread to some degree, but I missed that.
Is there a code example somewhere?
D/
On May 28, 2010, at 11:34 AM, James Carman wrote:
> Perhaps you would be interested in the other threads that have been
> going on where we discuss InheritableThreadLocal. In there Jeremy
> gave a good solution that would fix what you're seeing. Basically,
> you use the beforeExecute()/afterExecute() methods to set/clear the
> Application's ThreadLocal variable so that it's available during the
> execution of the task.
>
> On Fri, May 28, 2010 at 12:01 PM, Douglas Ferguson
> <do...@douglasferguson.us> wrote:
>> I'm still spinning my wheels on this one.
>>
>> Let me try to explain better..
>>
>> On the page I have
>>
>> @Inject DAOFactory
>> @Inject MyService
>>
>> On the DAOFactory I have
>>
>> @Inject DAO1
>> @Inject DAO2
>> etc...
>>
>> On MyService I have
>>
>> @Inject DAO1
>>
>> In my module I have
>>
>> bind(MyService.class).toInstance(new MyService());
>> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
>> bind(DAO1.class).in(Singleton.class);
>> bind(DAO2.class).in(Singleton.class);
>>
>> On the page I also have:
>>
>> genericWorkPool.submit(new Runnable() {
>>
>> @Override
>> public void run() {
>> try {
>> //Do stuff with DAOFactory -- works
>> //Do stuff with MyService -- Blow ups <<<---- See exception below
>> } catch (Throwable t) {
>> log.error("Error sending email on Signup: " + t.getMessage(), t);
>> }
>> }
>> }
>>
>> This is the error I get
>>
>> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
>> at org.apache.wicket.Application.get(Application.java:179)
>> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
>> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
>> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>>
>> I can't understand why DAOFactory would work ok but MyService wouldn't.
>>
>>
>> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>>
>> I'm using 1.4.8 (not the ITL version).
>>
>> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>>
>> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>>
>> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>>
>> I've tried these combinations:
>>
>> 1) @Inject into the page and then pass the reference to the constructor of the runnable
>> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>>
>> Neither works.
>>
>> D/
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Alex Objelean <al...@gmail.com>.
Yes, the link is here: http://pastebin.com/TyDrCCCr
Basically, you have to replace:
final ExecutorService service =
Executors.newSingleThreadScheduledExecutor();
with:
final Application app = Application.get();
final ExecutorService service = new ScheduledThreadPoolExecutor(1)
{
@Override
protected void beforeExecute(final Thread t, final Runnable r) {
Application.set(app);
};
@Override
protected void afterExecute(final Runnable r, final Throwable t)
{
Application.unset();
}
};
Alex
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235261.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
Is there an example of this that somebody could link me to?
On May 28, 2010, at 3:56 PM, Alex Objelean wrote:
>
> The idea is that with the first solution you don't have to clutter up each
> task's code:
> "1) use the beforeExecute()/afterExecute() methods to set/clear the
> Application's ThreadLocal variable so that it's available during the
> execution of the task. "
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235201.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Alex Objelean <al...@gmail.com>.
The idea is that with the first solution you don't have to clutter up each
task's code:
"1) use the beforeExecute()/afterExecute() methods to set/clear the
Application's ThreadLocal variable so that it's available during the
execution of the task. "
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235201.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
What are you agreeing with? I can't see the thread...
On May 28, 2010, at 3:30 PM, Alex Objelean wrote:
>
> Yes, I agree. I do prefer this solution too.
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235166.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Alex Objelean <al...@gmail.com>.
Yes, I agree. I do prefer this solution too.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/using-injected-services-in-a-child-thread-tp2233924p2235166.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by James Carman <ja...@carmanconsulting.com>.
That's what the other one did, but it used the callback methods to do
the set/unset. This way, you don't have to clutter up each task's
code.
On Fri, May 28, 2010 at 4:23 PM, Douglas Ferguson
<do...@douglasferguson.us> wrote:
> This worked for me..
>
>
> @Override
> public void run() {
> try {
> Application.set(app);
> //Do my long running operation
> } catch (Throwable t) {
> log.error("Error doing it...: " + t.getMessage(), t);
> }finally{
> Application.unset();
> }
> }
>
>
> Now, it's time to brainstorm as to how I could make this work generically...
>
>
> On May 28, 2010, at 11:34 AM, James Carman wrote:
>
>> Perhaps you would be interested in the other threads that have been
>> going on where we discuss InheritableThreadLocal. In there Jeremy
>> gave a good solution that would fix what you're seeing. Basically,
>> you use the beforeExecute()/afterExecute() methods to set/clear the
>> Application's ThreadLocal variable so that it's available during the
>> execution of the task.
>>
>> On Fri, May 28, 2010 at 12:01 PM, Douglas Ferguson
>> <do...@douglasferguson.us> wrote:
>>> I'm still spinning my wheels on this one.
>>>
>>> Let me try to explain better..
>>>
>>> On the page I have
>>>
>>> @Inject DAOFactory
>>> @Inject MyService
>>>
>>> On the DAOFactory I have
>>>
>>> @Inject DAO1
>>> @Inject DAO2
>>> etc...
>>>
>>> On MyService I have
>>>
>>> @Inject DAO1
>>>
>>> In my module I have
>>>
>>> bind(MyService.class).toInstance(new MyService());
>>> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
>>> bind(DAO1.class).in(Singleton.class);
>>> bind(DAO2.class).in(Singleton.class);
>>>
>>> On the page I also have:
>>>
>>> genericWorkPool.submit(new Runnable() {
>>>
>>> @Override
>>> public void run() {
>>> try {
>>> //Do stuff with DAOFactory -- works
>>> //Do stuff with MyService -- Blow ups <<<---- See exception below
>>> } catch (Throwable t) {
>>> log.error("Error sending email on Signup: " + t.getMessage(), t);
>>> }
>>> }
>>> }
>>>
>>> This is the error I get
>>>
>>> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
>>> at org.apache.wicket.Application.get(Application.java:179)
>>> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
>>> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
>>> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>>>
>>> I can't understand why DAOFactory would work ok but MyService wouldn't.
>>>
>>>
>>> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>>>
>>> I'm using 1.4.8 (not the ITL version).
>>>
>>> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>>>
>>> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>>>
>>> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>>>
>>> I've tried these combinations:
>>>
>>> 1) @Inject into the page and then pass the reference to the constructor of the runnable
>>> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>>>
>>> Neither works.
>>>
>>> D/
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
This worked for me..
@Override
public void run() {
try {
Application.set(app);
//Do my long running operation
} catch (Throwable t) {
log.error("Error doing it...: " + t.getMessage(), t);
}finally{
Application.unset();
}
}
Now, it's time to brainstorm as to how I could make this work generically...
On May 28, 2010, at 11:34 AM, James Carman wrote:
> Perhaps you would be interested in the other threads that have been
> going on where we discuss InheritableThreadLocal. In there Jeremy
> gave a good solution that would fix what you're seeing. Basically,
> you use the beforeExecute()/afterExecute() methods to set/clear the
> Application's ThreadLocal variable so that it's available during the
> execution of the task.
>
> On Fri, May 28, 2010 at 12:01 PM, Douglas Ferguson
> <do...@douglasferguson.us> wrote:
>> I'm still spinning my wheels on this one.
>>
>> Let me try to explain better..
>>
>> On the page I have
>>
>> @Inject DAOFactory
>> @Inject MyService
>>
>> On the DAOFactory I have
>>
>> @Inject DAO1
>> @Inject DAO2
>> etc...
>>
>> On MyService I have
>>
>> @Inject DAO1
>>
>> In my module I have
>>
>> bind(MyService.class).toInstance(new MyService());
>> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
>> bind(DAO1.class).in(Singleton.class);
>> bind(DAO2.class).in(Singleton.class);
>>
>> On the page I also have:
>>
>> genericWorkPool.submit(new Runnable() {
>>
>> @Override
>> public void run() {
>> try {
>> //Do stuff with DAOFactory -- works
>> //Do stuff with MyService -- Blow ups <<<---- See exception below
>> } catch (Throwable t) {
>> log.error("Error sending email on Signup: " + t.getMessage(), t);
>> }
>> }
>> }
>>
>> This is the error I get
>>
>> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
>> at org.apache.wicket.Application.get(Application.java:179)
>> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
>> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
>> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>>
>> I can't understand why DAOFactory would work ok but MyService wouldn't.
>>
>>
>> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>>
>> I'm using 1.4.8 (not the ITL version).
>>
>> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>>
>> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>>
>> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>>
>> I've tried these combinations:
>>
>> 1) @Inject into the page and then pass the reference to the constructor of the runnable
>> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>>
>> Neither works.
>>
>> D/
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
Even if I got that to work, it doesn't explain why some things using @Inject blow up and others don't.
There has to be a reason for this. Under what circumstances to an injected object need a reference to the Application?
D/
On May 28, 2010, at 11:34 AM, James Carman wrote:
> Perhaps you would be interested in the other threads that have been
> going on where we discuss InheritableThreadLocal. In there Jeremy
> gave a good solution that would fix what you're seeing. Basically,
> you use the beforeExecute()/afterExecute() methods to set/clear the
> Application's ThreadLocal variable so that it's available during the
> execution of the task.
>
> On Fri, May 28, 2010 at 12:01 PM, Douglas Ferguson
> <do...@douglasferguson.us> wrote:
>> I'm still spinning my wheels on this one.
>>
>> Let me try to explain better..
>>
>> On the page I have
>>
>> @Inject DAOFactory
>> @Inject MyService
>>
>> On the DAOFactory I have
>>
>> @Inject DAO1
>> @Inject DAO2
>> etc...
>>
>> On MyService I have
>>
>> @Inject DAO1
>>
>> In my module I have
>>
>> bind(MyService.class).toInstance(new MyService());
>> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
>> bind(DAO1.class).in(Singleton.class);
>> bind(DAO2.class).in(Singleton.class);
>>
>> On the page I also have:
>>
>> genericWorkPool.submit(new Runnable() {
>>
>> @Override
>> public void run() {
>> try {
>> //Do stuff with DAOFactory -- works
>> //Do stuff with MyService -- Blow ups <<<---- See exception below
>> } catch (Throwable t) {
>> log.error("Error sending email on Signup: " + t.getMessage(), t);
>> }
>> }
>> }
>>
>> This is the error I get
>>
>> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
>> at org.apache.wicket.Application.get(Application.java:179)
>> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
>> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
>> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>>
>> I can't understand why DAOFactory would work ok but MyService wouldn't.
>>
>>
>> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>>
>> I'm using 1.4.8 (not the ITL version).
>>
>> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>>
>> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>>
>> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>>
>> I've tried these combinations:
>>
>> 1) @Inject into the page and then pass the reference to the constructor of the runnable
>> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>>
>> Neither works.
>>
>> D/
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by James Carman <ja...@carmanconsulting.com>.
Perhaps you would be interested in the other threads that have been
going on where we discuss InheritableThreadLocal. In there Jeremy
gave a good solution that would fix what you're seeing. Basically,
you use the beforeExecute()/afterExecute() methods to set/clear the
Application's ThreadLocal variable so that it's available during the
execution of the task.
On Fri, May 28, 2010 at 12:01 PM, Douglas Ferguson
<do...@douglasferguson.us> wrote:
> I'm still spinning my wheels on this one.
>
> Let me try to explain better..
>
> On the page I have
>
> @Inject DAOFactory
> @Inject MyService
>
> On the DAOFactory I have
>
> @Inject DAO1
> @Inject DAO2
> etc...
>
> On MyService I have
>
> @Inject DAO1
>
> In my module I have
>
> bind(MyService.class).toInstance(new MyService());
> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
> bind(DAO1.class).in(Singleton.class);
> bind(DAO2.class).in(Singleton.class);
>
> On the page I also have:
>
> genericWorkPool.submit(new Runnable() {
>
> @Override
> public void run() {
> try {
> //Do stuff with DAOFactory -- works
> //Do stuff with MyService -- Blow ups <<<---- See exception below
> } catch (Throwable t) {
> log.error("Error sending email on Signup: " + t.getMessage(), t);
> }
> }
> }
>
> This is the error I get
>
> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
> at org.apache.wicket.Application.get(Application.java:179)
> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>
> I can't understand why DAOFactory would work ok but MyService wouldn't.
>
>
> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>
> I'm using 1.4.8 (not the ITL version).
>
> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>
> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>
> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>
> I've tried these combinations:
>
> 1) @Inject into the page and then pass the reference to the constructor of the runnable
> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>
> Neither works.
>
> D/
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
Going back to my original example..
With the Application.set() trick I am able to keep it from blow up, but why would "MyService" call Application.get() (and thus blow up).
When the DAOs don't. They are both @Inject and they are both setup in my guice module as "singleton"
D/
On May 28, 2010, at 11:01 AM, Douglas Ferguson wrote:
> I'm still spinning my wheels on this one.
>
> Let me try to explain better..
>
> On the page I have
>
> @Inject DAOFactory
> @Inject MyService
>
> On the DAOFactory I have
>
> @Inject DAO1
> @Inject DAO2
> etc...
>
> On MyService I have
>
> @Inject DAO1
>
> In my module I have
>
> bind(MyService.class).toInstance(new MyService());
> bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
> bind(DAO1.class).in(Singleton.class);
> bind(DAO2.class).in(Singleton.class);
>
> On the page I also have:
>
> genericWorkPool.submit(new Runnable() {
>
> @Override
> public void run() {
> try {
> //Do stuff with DAOFactory -- works
> //Do stuff with MyService -- Blow ups <<<---- See exception below
> } catch (Throwable t) {
> log.error("Error sending email on Signup: " + t.getMessage(), t);
> }
> }
> }
>
> This is the error I get
>
> org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
> at org.apache.wicket.Application.get(Application.java:179)
> at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
> at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
> at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
>
> I can't understand why DAOFactory would work ok but MyService wouldn't.
>
>
> On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
>
> I'm using 1.4.8 (not the ITL version).
>
> I have pass a runnable to an executer, how can I make use of classes that use @Inject?
>
> When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
>
> The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
>
> I've tried these combinations:
>
> 1) @Inject into the page and then pass the reference to the constructor of the runnable
> 2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
>
> Neither works.
>
> D/
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: using injected services in a child thread
Posted by Douglas Ferguson <do...@douglasferguson.us>.
I'm still spinning my wheels on this one.
Let me try to explain better..
On the page I have
@Inject DAOFactory
@Inject MyService
On the DAOFactory I have
@Inject DAO1
@Inject DAO2
etc...
On MyService I have
@Inject DAO1
In my module I have
bind(MyService.class).toInstance(new MyService());
bind(IDAOFactory.class).to(DAOFactory.class).in(Singleton.class);
bind(DAO1.class).in(Singleton.class);
bind(DAO2.class).in(Singleton.class);
On the page I also have:
genericWorkPool.submit(new Runnable() {
@Override
public void run() {
try {
//Do stuff with DAOFactory -- works
//Do stuff with MyService -- Blow ups <<<---- See exception below
} catch (Throwable t) {
log.error("Error sending email on Signup: " + t.getMessage(), t);
}
}
}
This is the error I get
org.apache.wicket.WicketRuntimeException: There is no application attached to current thread pool-13-thread-3
at org.apache.wicket.Application.get(Application.java:179)
at org.apache.wicket.guice.GuiceProxyTargetLocator.locateProxyTarget(GuiceProxyTargetLocator.java:73)
at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:317)
at WICKET_com.conducive.logic.buzzbox.BuzzboxEmailGenerator$$EnhancerByCGLIB$$1171cfab.generateFor(<generated>) <-- this is "MyService"
I can't understand why DAOFactory would work ok but MyService wouldn't.
On May 27, 2010, at 6:53 PM, Douglas Ferguson wrote:
I'm using 1.4.8 (not the ITL version).
I have pass a runnable to an executer, how can I make use of classes that use @Inject?
When I try to do so, it blows up saying "There is no application attached to current thread pool-13-thread-1"
The confusing thing is that I inject 2 DAOs and 1 service. The 2DAOs work just fine but the service blows up.
I've tried these combinations:
1) @Inject into the page and then pass the reference to the constructor of the runnable
2) Construct the service in the Runnable and call @InjectorHolder.getInjector().inject(service)
Neither works.
D/