-
1. Re: Spawn a new thread in ServiceMix
ffang Apr 16, 2011 8:31 AM (in response to chungyeung)Hi,
You need elaborate which component you used in servicemix, the code how you create the thread, otherwise we can't give useful help.
Freeman
-
2. Re: Spawn a new thread in ServiceMix
chungyeung Apr 17, 2011 7:35 AM (in response to chungyeung)Hi,
Thank you for the reply. I use ServiceMix version 4.3.1-fuse-01-09 together with Spring DM and camel. The service basically waits for a message from a queue on "tcp.//localhost:61610" using camel component with the following defined route:
<camel:route>
<camel:from uri="jms:queue:testServer"/>
<camel:to uri="testServer"/>
</camel:route>
The code for the testServer is as follows:
@Service(value = "testServer")
public class TestServerImpl implements TestServer, ApplicationContextAware {
....
public Result getPrice(final String clientRef) {
....
new Thread() {
@Override
public void run() {
....
try {
Thread.sleep(500);
....
} catch (..) {
....
}
}
}.start();
....
}
....
}
I got the exception:
Exception in thread "Thread-40" java.lang.NullPointerException at TestServiceImpl$2.run(TestServiceImpl.java:105)
The position 105 is the code for the new thread.
It would be great if you could show me how I can create a new thread without getting this exception.
Thanks
Chung-Yeung
-
3. Re: Spawn a new thread in ServiceMix
ffang Apr 17, 2011 9:21 AM (in response to chungyeung)Hi,
You're using anonymous inner class
new Thread() {
@Override
public void run() {
//here throw NPE
}.start();
So exception in thread "Thread-40" java.lang.NullPointerException at TestServiceImpl$2.run(TestServiceImpl.java:105)
means there's a NPE in your thread run method, Line 105 here can't exactly point to the error line as you're using anonymous inner class .
you need check your code in run method.
Freeman
Edited by: ffang on Apr 17, 2011 1:21 PM
-
4. Re: Spawn a new thread in ServiceMix
chungyeung Apr 18, 2011 2:41 PM (in response to ffang)Hi,
Thanks for the hint. You are right. It was not the thread. The bean runs fine on a standalone application but throws an exception when it runs under a service in ServiceMix. I found out that the problem was with the Spring application context that has not been set even though the bean was declared as implementation of ApplicationContextAware. I had a similar implementation of a bean for ApplicationContextAware which I referred to from an external Jar in my service. The application context was set for that bean. May be I have missed something. Should I start a new thread for this question?
Thanks
-
5. Re: Spawn a new thread in ServiceMix
ffang Apr 18, 2011 8:22 PM (in response to chungyeung)Hi,
Yeah, start a new thread for a new question with appropriate question title is better.
You need post your whole bean.xml to that thread.
Freeman
-