J-Integra® maintains a pool of threads for handling requests from COM objects. By default, J-Integra® allows a maximum of twenty threads for handling such requests, however you may change the maximum by setting the JINTEGRA_MAX_REQUEST_HANDLERS property to the number you want, as in:
java -DJINTEGRA_MAX_REQUEST_HANDLERS=50 YourMainProgram |
J-Integra® creates such threads as and when they are required. However, it does not mean that twenty threads will be created on start up. It creates the first thread when the first remote request comes in. If a second request comes in, and the first thread is busy servicing a request, J-Integra® will create a second thread to handle the second request, and so on, up to the maximum of twenty (by default). If you are using an application server and don't see the number of threads is increased after setting the JINTEGRA_MAX_REQUEST_HANDLERS property, it means that your application server is not configured to handle sufficient threads. Therefore also make sure to properly configure your application server.
These threads will normally terminate after five minutes of not being used, however you can increase this by setting the JINTEGRA_IDLE_THREAD_TIMEOUT property (in milliseconds).
If you are interested in seeing J-Integra®'s thread allocation mechanism in action, you can run J-Integra® with internal logging enabled (set the JINTEGRA_LOG_LEVEL property to 3, the maximum). The following Visual BASIC code makes a callback to a Java object (p1 is a Java object):
Public Sub method1(ByVal p1 As Object) |
This is an excerpt from the log, showing what happens. The IDispatch::GetIDsOfNames is handled internally by J-Integra®, using reflection.
13:05:20+: ObjectExporter0 received an unfragmented request with call ID 1 |
If you wish to prevent the same method in your Java object from being invoked more than once at the same time by COM objects, then simply use the standard Java synchronized keyword, which will cause method invocations to block if another object is already invoking the method.
If you wish to have multiple calls from the same COM client thread result in the same J-Integra® runtime Java thread being used to invoke the corresponding methods onto Java objects, then you can set the JINTEGRA_MATCH_THREADS property. This will result in a dedicated thread being allocated for each COM client thread -- you may need to modify the default maximum number of threads and the time the threads sit idle before terminating, by setting the appropriate properties. This property is not currently supported when making IDispatch (late-bound) calls in Native Mode.