Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 282201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:16:07+00:00 2026-05-12T05:16:07+00:00

I have several classes that use the same JNI library, called jni. In each

  • 0

I have several classes that use the same JNI library, called “jni”. In each of those classes, I have a System.loadLibrary() call in the class’s static initializer:

Class class1 {
    static{
        System.loadLibrary("jni");
    }
    ...
}

Class class2 {
    static{
        System.loadLibrary("jni");
    }
    ...
}

The only problem is, I only want System.loadLibrary() to be called once, since it can take a while. Is there an easy and clean way to prevent multiple loadings of the same library?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:16:08+00:00Added an answer on May 12, 2026 at 5:16 am

    If the library has already be loaded any subsequent calls to load the same library will be ignored.

    System.loadLibrary:

    Loads the system library specified by
    the libname argument. The manner in
    which a library name is mapped to the
    actual system library is system
    dependent.

    The call System.loadLibrary(name) is
    effectively equivalent to the call

     Runtime.getRuntime().loadLibrary(name)
    

    Runtime.loadLibrary:

    Loads the dynamic library with the
    specified library name. A file
    containing native code is loaded from
    the local file system from a place
    where library files are conventionally
    obtained. The details of this process
    are implementation-dependent. The
    mapping from a library name to a
    specific filename is done in a
    system-specific manner.

    First, if there is a security manager,
    its checkLink method is called with
    the libname as its argument. This may
    result in a security exception.

    The method System.loadLibrary(String)
    is the conventional and convenient
    means of invoking this method. If
    native methods are to be used in the
    implementation of a class, a standard
    strategy is to put the native code in
    a library file (call it LibFile) and
    then to put a static initializer:

     static { System.loadLibrary("LibFile"); }
    

    within the class declaration. When the
    class is loaded and initialized, the
    necessary native code implementation
    for the native methods will then be
    loaded as well.

    If this method is called more than
    once with the same library name, the
    second and subsequent calls are
    ignored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several classes that implement the same interface. interface IBidManager<E> where E :
I have several classes (A, B, C, ...) that all use a List<AnotherClass> to
I have a Role and several classes that mix-in the role. The Role class
I have several classes that I serialize/deserialize, each with a number of properties, some
If I have interface IFoo, and have several classes that implement it, what is
I have several service classes that have static methods and offer a service to
I have a need for methods in several classes that must always follow a
I have a block of code that basically intializes several classes, but they are
Let's say I have a Base class and several Derived classes. Is there any
I have several classes that need to load some properties files, and I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.