How to use JNI correctly with Java EE (Servlets) o

2019-08-23 17:58发布

问题:

I am trying to understand what is the correct way of usage JNI from Servlet.

As I understand there are several problems:

  1. If native DLL crashes, it will bring down whole app server
  2. If DLL is loaded by one class loaded, than another class loader won't be able to load and use it.

I searched internet and found couple of possible solution

  • Create standalone JMS enabled application and use JMS in Servlet to communicate with it.
  • Run standalone server, load in it JNI and talk to it through RMI
  • Use Java Connector architecture

I would appreciate any information on this subject, what is best practice in this case?

P.S. I am not sure whether it's important, but the application which needs to use native DLL runs on JBoss.

回答1:

I would absolutely not run a JNI-based tool in a Java EE app server. Your suggestion for using JMS is a good one. You could create a service around message based Beans to respond to messages dispatched by your external service:

http://oreilly.com/catalog/entjbeans3/chapter/ch13.html

Here is the link to the Oracle Java EE documentation on Message-driven beans: http://download.oracle.com/javaee/5/tutorial/doc/bnbpk.html

I would suggest getting two JBoss servers to talk to one another over JMS is easier than writing a JCA adapter, and that JMS message-driven beans are a cleaner interface. JCA doesn't seem to be evolving at all - there doesn't seem to be any great implementation tutorials (that's just my perception).