Application Performance Using JNI for RFID

AID: 4597
  • Status: Published

1600 points

Introduction
Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java Virtual Machine) can recognize the symbols exported by the native program. It defines how functions are to be named. Also it defines how to pass different types of data variable between the native code and Java code.

We had to implement RFID in one of our Java application. According to the application demand we choose to use network based RFID scanners. The manufacturer of the scanner supplied us with C++ SDK along with the scanner. Since the SDK is for C++ we wrote a JNI to integrate it with our application.

The Setback
The JNI is written with four functions, Connect_Scanner, Read_RFID, Clear_Buff and Disconnect_Scanner.

Connect_Scanner: This is to connect to the scanner and expects the IP address and Port number from the Java code. On success or failure of the connection this function returns a status code accordingly.

Read_RFID: On a successful connection the Java code spawns a new thread and calls this function in a continuous loop. Internally the C++ code calls a API function provided by the SDK. One of the parameter of the function was a type struct array. When the API function returns the struct array contains all the RFIDs scanned.

Clear_Buff: So that the same RFID is not scanned more than once a buffer temporarily holds all the scanned RFIDs. This function is used to clear this buffer.

Disconnect_Scanner: This function is called to disconnect the scanner from the application.

We found when we called Read_RFID from the Java code it took little more than 4secs to return. Otherwise when we called the function from the native code itself it was just about 1 to 2 milliseconds. The main reason could be because of the way strings are handled in Java vis-à-vis C++.

The Solution

We compiled the native code in to a separate executable and connected the Java application with a local loop socket. The native executable listens on IP 127.0.0.1 and port 100. The Java code makes a socket client connection to the executable. The functions are then called through the socket.    
Asked On
2011-02-26 at 01:37:45ID4597
Tags

JNI

,

Java

,

TCP

,

Socket

,

Native Library Java

Topic

Java Programming Language

Views
1011

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Java Experts

  1. for_yan

    893,063

    Sage

    1,000 points yesterday

    Profile
    Rank: Genius
  2. CEHJ

    258,666

    Guru

    1,050 points yesterday

    Profile
    Rank: Savant
  3. mccarl

    93,106

    Master

    3,000 points yesterday

    Profile
    Rank: Wizard
  4. girionis

    90,218

    Master

    0 points yesterday

    Profile
    Rank: Genius
  5. dpearson

    86,565

    Master

    498 points yesterday

    Profile
    Rank: Guru
  6. chaituu

    62,368

    Master

    0 points yesterday

    Profile
    Rank: Sage
  7. gudii9

    57,252

    Master

    1,000 points yesterday

    Profile
    Rank: Master
  8. sharonseth

    47,283

    501 points yesterday

    Profile
    Rank: Master
  9. ksivananth

    39,726

    0 points yesterday

    Profile
    Rank: Genius
  10. gordon_vt02

    28,625

    0 points yesterday

    Profile
    Rank: Guru
  11. simonet

    27,400

    0 points yesterday

    Profile
    Rank: Wizard
  12. mrcoffee365

    23,455

    0 points yesterday

    Profile
    Rank: Genius
  13. dravidnsr

    20,609

    501 points yesterday

    Profile
    Rank: Sage
  14. objects

    20,284

    0 points yesterday

    Profile
    Rank: Savant
  15. knsp

    18,558

    0 points yesterday

    Profile
  16. gurvinder372

    18,104

    0 points yesterday

    Profile
    Rank: Genius
  17. santhanasamy

    16,800

    0 points yesterday

    Profile
    Rank: Master
  18. mplungjan

    16,568

    0 points yesterday

    Profile
    Rank: Savant
  19. stmani2005

    15,089

    1,000 points yesterday

    Profile
    Rank: Master
  20. ramazanyich

    14,200

    0 points yesterday

    Profile
    Rank: Sage
  21. CPColin

    13,836

    0 points yesterday

    Profile
    Rank: Guru
  22. arioh

    13,298

    0 points yesterday

    Profile
    Rank: Guru
  23. zzynx

    12,280

    0 points yesterday

    Profile
    Rank: Genius
  24. alexey_gusev

    12,000

    0 points yesterday

    Profile
    Rank: Genius
  25. Gertone

    11,752

    0 points yesterday

    Profile
    Rank: Genius

Hall Of Fame