I am a c++ programmer and support a multithreaded messaging api. My swig project uses SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON preprocessor definition.

I noticed that the message rate coming into the java application is very slow compared to what we get when directly using the c++ interface. I also noticed that each update

Was coming into java on a new thread id while my c++ api only has 4 threads. I also presumed that the message rate is so slow because with each update a new thread has to be spawned.

So I removed the SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON definition and now the updates come on 4 threads only and the message rate has quadrupled. However, the application

Now hangs on shutdown. How do I go about fixing this? I am ok with forcing the application to shutdown if I can detect when the Java app has exited but I to figure out how. I don’t want the user to have

To write any extra java code, I would like to figure this out on the c++ side. Any help would be greatly appreciated.

This message is for the named person's use only. This communication is for
informational purposes only and has been obtained from sources believed to
be reliable, but it is not necessarily complete and its accuracy cannot be
guaranteed. It is not intended as an offer or solicitation for the purchase
or sale of any financial instrument or as an official confirmation of any
transaction. Moreover, this material should not be construed to contain any
recommendation regarding, or opinion concerning, any security. It may
contain confidential, proprietary or legally privileged information. No
confidentiality or privilege is waived or lost by any mistransmission. If
you receive this message in error, please immediately delete it and all
copies of it from your system, destroy any hard copies of it and notify the
sender. You must not, directly or indirectly, use, disclose, distribute,
print, or copy any part of this message if you are not the intended
recipient.  Any views expressed in this message are those of the individual
sender, except where the message states otherwise and the sender is
authorized to state them to be the views of any such entity.

Securities products and services provided to Canadian investors are offered
by ITG Canada Corp. (member CIPF and IIROC - Investment Industry Regulatory
Organization of Canada), an affiliate of Investment
Technology Group, Inc.

Investment research products and services are produced and offered by
ITG Investment Research, Inc. and not ITG Inc. (a FINRA member firm and
SIPC member).

ITG Inc. and/or its affiliates reserves the right to monitor and archive
all electronic communications through its network.