Greetings, I could not provide all the details in the question, so here are the key details.
I have a native dll (and a corresponding .so) wrapping a static library, which is created by Eiffel programming language. I've written a C++ wrapper around the static lib, and I've successfully exposed this to Java. However, if I use this dll in a web application, things will become kinda complicated. The problem is multiple java threads will access the same C++ code, where native context(?) is kept between calls by different classes & instances. In order to use functionality from the Eiffel code, one has to initialize Eiffel runtime from C++ and then use Eiffel libraries to make use of Eiffel classes from C++. Unfortunately, this means that all incoming requests to Java server side end up in a single location in C++ (within native dll), where there is only one Eiffel runtime. This situation forces me to make the whole Eiffel runtime thread safe, and only one operation by one Java thread can use Eiffel code, by passing through JNI. I have a feeling that this may quickly become a scalability issue.
I feel that I may need a pool of processes, each loading a copy of the same dll(or .so under *nix) which will be served to incoming threads from Java. So once the shared library is loaded, C++ code will create, say 10 processes, and incoming threads from Java side will be allocated to these processes via C++ code. The flow of events would be like this:
Java thread accesses native code (c++) in shared library. Native code checks which processes are available from the process pool makes use of one of the processes via ipc, marking it busy (probably using a thread?)
This is the only cross platform way I could think of to safely load the same piece of code (Eiffel runtime and eiffel classes) without any thread safety issues.
This is all due to Eiffel runtime being an expensive, and global component, which I must expose via JNI.
Or should I simply go with thread safe operations, where only one thread is served from JNI at any time? Is there any trick I can do with Java to create lightweight isolated jvm like containers each using only a single Eiffel runtime?
Your feedback would be much appreciated.
Best Regards Seref