• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling native methods  RSS feed

 
P. Ingle
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I need to call some native methods (written in C++) fron my DAO methods.
How do I do this?
How do I package it and deploy it (jars and c++ code executable)?
Lastly, is this a good idea to be calling native methods? I know exactly which environment my code will be running (it's not downloadable code where I need to worry about client system) Or should I just invest time in converting the c++ code to Java (which is a viable option at this point)

Thanks,
P.Ingle
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ingle,


Lastly, is this a good idea to be calling native methods? I know exactly which environment my code will be running (it's not downloadable code where I need to worry about client system)

If you intend to use jni for calling native methods, then you have to plan little bit more carefully, especially if the native code runs on the server. If the C++ app throws an exception that is not properly handled in your java side, then it will mostly crash the jvm. The app server will die and all other applications deployed on that servers would die suddenly as well. Data will be lost and the damages might be very costly. I remember working for such a project that used jni but that was client code and it didn�t affect the server.

Or should I just invest time in converting the c++ code to Java (which is a viable option at this point)

Again if the server might be affected I would rather consider rewriting the legacy application in java. Another work around would be to wrap your C++ code with a layer of CORBA objects and let your java server side talking to the legacy app over the IIOP protocol. But this could be more complex and could lead to new software purchase or performance problems.
Regards.
 
Sachin Patil
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think webservice might solve the problem. Create webservice in C++ & call it from java code. i assume you not mantaining state.
 
Sachin Patil
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Valentin Tanase:
If the C++ app throws an exception that is not properly handled in your java side, then it will mostly crash the jvm.


In this case we can use classes which call native code, as activable objects. So even if the C++ app throws exception, only the activable object will get destroyed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!