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

  • SEARCH
  • Home
  • 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 4051612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:13:00+00:00 2026-05-20T14:13:00+00:00

My problem is the following; I have a class that uses non-static native methods

  • 0

My problem is the following; I have a class that uses non-static native methods for communicating over a serial port

public class Serial{
    final static int NOT_INITIALIZED = 0;
    final static int INITIALIZED = 1;

    private int instanceId;
    private String errorString;

    private native int initPort(String port);
    private native int termPort(int instanceId);
    private native int getState(int instanceId);
    private native int readPort(int instanceId);
    private native int writePort(int instanceId);

    /*... publically accessible methods follow */
}

Thus multiple classes can be instantiated, each with a specific serial port. The reason why I’m doing it this way is that it allows you to set the “errorString” field from the JNI code (when an error occurs) for the instance that called the JNI code.

I have learned that multiple instances on the same JVM will share the same JNI dll. So any global variables defined in the dll will be shared by multiple instances. For this reason communication handles and state variables are stored in an global array of structures. When initPort() is called, the instanceId field is set to an array index that contains the port handle and state (INITIALIZED or NOT_INITIALIZED).

What I do not understand is how the dll functions are shared by multiple instances. Do they each get their own copy of the function, or will calling the same function simultaneously cause errors?

  • 1 1 Answer
  • 1 View
  • 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-20T14:13:00+00:00Added an answer on May 20, 2026 at 2:13 pm

    There is one copy of each function. Each call occurs with a separate stack containing local variables etc.

    Your functions may be thread-safe or not thread-safe. If not thread-safe, calling even different methods simultaneously from multiple threads may be harmful. You know they access global variables, but don’t mention whether you know of any synchronization. Look for documentation stating that the class and its methods are intended to be thread-safe.

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

Sidebar

Related Questions

I have a UITableView class that uses the following methods to call a loading
Today I ran into the following problem with NUnit. I have a class, that
Good day, I have the following problem: class B extends class A and methods
I have the following helper class (simplified): public static class Cache { private static
I have the following problem: I have the class: class Word(object): def __init__(self): self.id
I have the following problem. I have a class named A in which I
I have the following problem with inheritance and templates: class Base {}; class Deriv
I have the following tricky problem: I have implemented a (rather complicated) class which
I have an error in map iterators. The problem is the following: class JacobianCol
I´m having the following problem: I have 2 classes (A and B). The class

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.