I am using Netbeans to build a java web project (tomcat 6.02 based) which loads a c++ native dll. I am using Jace
library which wraps JNI.
In my java code I have a static callback function which I call from c++ code. I am trying to invoke this callback in a new thread using boost.Thread but tomcat just dies without any message or crash report when I do. However if I call the function directly it works fine.
Can you please suggest what might be wrong?
below is my c++ code that causes crash:
//from native method:
for (int i = 0; i < 10; ++i)
{
MyFunctor func;
boost::thread t(func);
}
below is my c++ code that works fine:
//from native method:
for (int i = 0; i < 10; ++i)
{
MyFunctor func;
func();
}
Functor class (which causes the crash):
class MyFunctor
{
public:
void operator ()() const
{
ArrayList orders, trades;
//...Fill the above ArrayLists;
jace::proxy::test::CallBackTest::callbackFunc(orders, trades);
}
}
following is my java code:
public class CallBackTest {
public static void callbackFunc(ArrayList arraylist, ArrayList arraylist1) {
//System.out.println(); the two arraylists;
}
}
EDIT:
Strangely, following code also works. That is, if I invoke the functor once and then create multiple threads, there is no crash. Also this crash only happens in Tomcat and not if I make a standalone java application. Can anybody please explain why this happens?
MyFunctor func1;
func1();
for (int i = 0; i < 10; ++i)
{
MyFunctor func;
boost::thread t(func);
}