JNI£¨Java Native Interface£©
JNIÊÇJava Native InterfaceµÄËõд¡£´ÓJava 1.1¿ªÊ¼£¬Java Native Interface (JNI)±ê×¼³ÉΪjavaƽ̨µÄÒ»²¿·Ö£¬ËüÔÊÐíJava´úÂëºÍÆäËûÓïÑÔдµÄ´úÂë½øÐн»»¥¡£JNIÒ»¿ªÊ¼ÊÇΪÁ˱¾µØÒѱàÒëÓïÑÔ£¬ÓÈÆäÊÇCºÍC++¶øÉè¼ÆµÄ£¬µ«ÊÇËü²¢²»·Á°ÄãʹÓÃÆäËûÓïÑÔ£¬Ö»Òªµ÷ÓÃÔ¼¶¨ÊÜÖ§³Ö¾Í¿ÉÒÔÁË¡£
ʹÓÃjavaÓë±¾µØÒѱàÒëµÄ´úÂë½»»¥£¬Í¨³£»áɥʧƽ̨¿ÉÒÆÖ²ÐÔ¡£µ«ÊÇ£¬ÓÐЩÇé¿öÏÂÕâÑù×öÊÇ¿ÉÒÔ½ÓÊܵģ¬ÉõÖÁÊDZØÐëµÄ£¬±ÈÈ磬ʹÓÃһЩ¾ÉµÄ¿â£¬ÓëÓ²¼þ¡¢²Ù×÷ϵͳ½øÐн»»¥£¬»òÕßΪÁËÌá¸ß³ÌÐòµÄÐÔÄÜ¡£JNI±ê×¼ÖÁÉÙ±£Ö¤±¾µØ´úÂëÄܹ¤×÷ÔÚÈκÎJava ÐéÄâ»úʵÏÖÏ¡£
Ò»¡¢JNI£¨Java Native Interface£©µÄÉè¼ÆÄ¿µÄ
·The standard Java class library may not support the platform-dependent features needed by your application.
·You may already have a library or application written in another programming language and you wish to make it accessible to Java applications
·You may want to implement a small portion of time-critical code in a lower-level programming language, such as assembly, and then have your Java application call these functions
¶þ¡¢JNI£¨Java Native Interface£©µÄÊéд²½Öè
·±àд´øÓÐnativeÉùÃ÷µÄ·½·¨µÄjavaÀà
·Ê¹ÓÃjavacÃüÁî±àÒëËù±àдµÄjavaÀà
·Ê¹ÓÃjavah ?jni javaÀàÃûÉú³ÉÀ©Õ¹ÃûΪhµÄÍ·Îļþ
·Ê¹ÓÃC/C++ʵÏÖ±¾µØ·½·¨
·½«C/C++±àдµÄÎļþÉú³É¶¯Ì¬Á¬½Ó¿â
·ok
1) ±àдjava³ÌÐò£º
ÕâÀïÒÔHelloWorldΪÀý¡£
´úÂë1£º
class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}
ÉùÃ÷native·½·¨£ºÈç¹ûÄãÏ뽫һ¸ö·½·¨×öΪһ¸ö±¾µØ·½·¨µÄ»°£¬ÄÇôÄã¾Í±ØÐëÉùÃ÷¸Ä·½·¨ÎªnativeµÄ£¬²¢ÇÒ²»ÄÜʵÏÖ¡£ÆäÖз½·¨µÄ²ÎÊýºÍ·µ»ØÖµÔÚºóÃæ½²Êö¡£
Load¶¯Ì¬¿â£ºSystem.loadLibrary("hello");¼ÓÔض¯Ì
Ïà¹ØÎĵµ£º
ʲôÊÇsocket
³¤Á¬½ÓÓë¶ÌÁ¬½Ó
Ëùν³¤Á¬½Ó£¬Ö¸ÔÚÒ»¸öTCPÁ¬½ÓÉÏ¿ÉÒÔÁ¬Ðø·¢ËͶà¸öÊý¾Ý°ü£¬ÔÚTCPÁ¬½Ó±£³ÖÆڼ䣬Èç¹ûûÓÐÊý¾Ý°ü·¢ËÍ£¬ÐèҪ˫·½·¢¼ì²â°üÒÔά³Ö´ËÁ¬½Ó£¬Ò»°ãÐèÒª×Ô¼º×öÔÚÏßά³Ö¡£
¶ÌÁ¬½ÓÊÇָͨÐÅË«·½ÓÐÊý¾Ý½»»¥Ê±£¬¾Í½¨Á¢Ò»¸öTCPÁ¬½Ó£¬Êý¾Ý·¢ËÍÍê³Éºó£¬Ôò¶Ï¿ª´ËTCPÁ¬½Ó£¬Ò»°ãÒøÐж¼Ê¹ÓöÌÁ¬½Ó¡£
±ÈÈçht ......
ת×Ôhttp://blog.csdn.net/kabini/archive/2007/07/25/1707747.aspx
Ç°ÑÔ
±¾ÎÄÇ°ÑÔ²¿·ÖΪÎÒµÄһЩ¸ÐÏ룬Èç¹ûÄãÖ»¶Ô±¾ÎĽéÉܵÄJavaʵÓü¼ÇɸÐÐËȤ£¬¿ÉÒÔÌø¹ýÇ°ÑÔÖ±½Ó¿´ÕýÎĵÄÄÚÈÝ¡£
±¾ÎĵÄд×÷¶¯»úÀ´Ô´ÓÚ×î½ü½Ó¸øÈ˼ҰïæдµÄÒ»¸öС³ÌÐò£¬Ö÷ÒªÓÃÓÚ¹ÜÀí·ÖÆÚ¸¶¿îµÄ»õ¿îµÄһϵÁйÜÀí£¬°üÀ¨¹ýÆÚ¿îµÄ¼Í¼£¬¹ýÆÚ¿îÀûÏ ......
1. Ó¦Ó÷¶Î§
±¾¹æ·¶Ó¦ÓÃÓÚ²ÉÓÃJ2EE¹æ·¶µÄÏîÄ¿ÖУ¬ËùÓÐÏîÄ¿ÖеÄJAVA´úÂ루º¬JSP£¬SERVLET£¬JAVABEAN£¬EJB£©¾ùÓ¦×ñÊØÕâ¸ö¹æ·¶¡£Í¬Ê±£¬Ò²¿É×÷ΪÆäËüÏîÄ¿µÄ²Î¿¼¡£
2. Éè¼ÆÀàºÍ·½·¨
2.1 ´´½¨¾ßÓкÜÇ¿ÄÚ¾ÛÁ¦µÄÀà
·½·¨µÄÖØÒªÐÔÍùÍù±ÈÀàµÄÖØÒªÐÔ¸üÈÝÒ×Àí½â£¬·½·¨ÊÇÖ¸Ö´ÐÐÒ»¸öͳһº¯ÊýµÄÒ»¶Î´úÂë¡£Àà³£± ......
Problem: email thread is hanging at socket read
Today we found a email problem in production, all of the mail threads (3 threads) are hanging/sitting/blocking at same point
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
......
ÓÐЩʱºò,ҪдһЩ³ÌÐò,ÔÚ JAVA ÀïÃæºÃÄÑʵÏÖ, µ«Èç¹ûʹÓÃÆäËü±à³ÌÓïÑÔÈ´ÓֱȽÏÈÝÒ×ʱ,ÎÒÃDz»·Áͨ¹ý JNI À´Èò»Í¬ÓïÑԵijÌÐò¹²Í¬Íê³É.
JNI µÄ½Ì³Ì, ÍøÉÏ C µÄ±È½Ï¶à,Java Ò²ÌṩÁË javah.exe Ϊ C ÓïÑ﵀ JNI ³ÌÐòÉú³ÉÍ·Îļþ, Èç¹ûÄãÊÇÒ»¸ö Delphi ±à³ÌÔ±, ÄÜ·ñÈà JAVA Óë Delphi ³ÌÐò½»»¥ÄØ? ´ð°¸Êǿ϶¨µÄ,½ñÌìÎÒÃǾÍÀ´ ......