On Thu, 12 Jun 2014 12:10:23 -0700, Phil Smith <[email protected]> wrote:
>We have a very simple API that we'd like to enable for use from WAS >applications on z/OS. You ought to be aware that typically in a WAS, you have many threads running alongside each other. If you will be calling your API from several different threads in parallel, you need to make sure your code is thread-safe. Or you need to serialise access to it. > Currently we support any standard language that calls us with an OS/360-style > plist, passing pointers to character strings and to fullword lengths of those > strings. That is doable in JNI too. I am sure Steve Comstock will chime in where multi-language calling conventions are involved... >From my reading, it appears that JNI is the way to go here. I know that JNI is >considered A Bad Thing (to quote my manager), but reading >http://en.wikipedia.org/wiki/Java_Native_Interface#Pitfalls doesn't leave me >concerned-none of those seem like anything that will affect us. JNI can be brittle if not coded properly. You are responsible yourself for correctly managing object references and for releasing them at the right time. You may want to do some reading on the subject. I started with "The Java™ Native Interface - Programmer’s Guide and Specification" by Sheng Liang. This book has some age to it, but is still valid. >So it all seems pretty straightforward, but if someone had a trivial example >they could share, that would help. I may have a few helper functions in C that should make coding a bit easier. Contact me off-line at jan dot moeyersons at gfi dot be if you want. > >Questions: > >1) Is it reasonable to expect that a Java program running in batch >(assuming that's even a possible environment?) could use the same JNI shims? In fact batch will probably be easier, because WAS will not interfere with your threads. Oh, and don't forget JZOS makes it very easy to fire up your Java batch programs. >2) What other pitfalls should we expect? Lost or forgotten object references will cause memory leaks. Exception handling is NOT automatic. You can throw and catch exceptions in your JNI code, but you have to be aware that throwing an exception does not interrupt the flow of your C code; you need to cater for that. Make sure you use the proper functions to get and put data in your Java objects; they depend upon the type of data. >3) What questions am I not asking that I should be? Not sure about that one... Cheers, Jantje. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
