Question on JNI Instances

Hi!
My Native DLL is basically involved in card reader functions. One of its methods is to be able to initialized a port, given an port number. A JNI proj was created to be able to use this DLL.
The java app that uses this needs 2 instances of the JNI proj, say jniTest1 and jniTest2. I tried initializing 2 different portnumbers for this instances, jniTest1 -> 2560 and jniTest2 -> 2561.
I tried accessing the method of each instance, jniTest1.readCard() and jniTest2.readCard(). But the value is the card data on port 2561.
Is this because the native DLL was loaded only once onto JVM? Is there a way to create 2 different instances of JNI proj? eg jniTest1 -> assigned to port 2560 and jniTest2 - 2561.
Any help will be appreciated
Mao

1. Your wording is vague: "Jni Proj" means nothing - either in java or in C.
2. You can only load one instance of a dll.
3. What you MIGHT be able to do is create your DLL code so that it is re-entrant/multithreadable, and use the same code on different instances of data.

Similar Messages

  • Some questions on JNI Specification(s)

    Which is the definitive spec? Is it the book "Programmer's Guide and
    Specification" (Guide) by Sheng Liang, or the online doc "Specification" v1.5
    (Spec)? The trouble is they don't agree on some matters. It's not simply a
    question of which is right, but rather what various JVM vendors have
    regarded as correct (regarding the Spec or the Guide as normative) at
    various points in time. I'm intending my code to be portable across multiple
    platorms and vendors, so it depends to which document they've worked. Do I
    have to program within the intersection of the two specs?
    The big one is that In the online Spec, it says that only ExceptionOccurred(),
    ExceptionDescribe(), and ExceptionClear() can be called when an exception
    is pending (end of Chapter 2). But the Guide (11.8.2) lists several other
    functions, among them ExceptionCheck(). For instance, according to the
    Guide if I call DeleteLocalRef() with a valid argument, nothing bad will
    happen, but according to the online Spec I could heading into crashes or
    other forms of Undefined Behaviour because there might be a pending
    exception. (Having been coding according to the Spec, the Guide now
    implies I could afford to have been a lot less cautious, so if the Guide is
    normative I can happily rip out lots careful error-handling code.)
    One apparently exception-unsafe function is PopLocalFrame(), which
    makes it unique amongst the resource cleanup functions. Is this
    accurate? Is there a reason for this?
    To clarify, what are all the functions that might FatalError() due to
    inability to allocate LocalRefs? Is it anything that returns a LocalRef
    except NewLocalRef (which just returns NULL and posts an exception)?
    What about PopLocalFrame() with a non-NULL argument?
    With those functions that take JNI Version parameter, will the resulting
    JNIEnv only have those function table entries for that version, or the
    most recent one? (i.e. is the supplied version a request for a minimum,
    or more exact)? If the former, does this mean that the JNI version
    hierarchy is guaranteed never to fork, so there is no ambiguity over the
    "latest version"? (My library may create a JVM or attach to a thread in
    a variety of circumstances, and it may not be possible to know what the
    most appropriate version to request is; I'm hoping the JNI just Does The
    Right Thing and saves me some trouble). The same holds for the JavaVM
    interface.
    For RegisterNatives, the Spec says the functions passed in must
    "nominally" have sig
    ReturnType (*)(JNIEnv*, jobject objectOrClass,...);
    Does this actually mean they should use a va_list and the C calling
    convention, rather than JNICALL and explicit params (as in "ordinary"
    native methods)?
    Thanks for your help
    John

    > With those functions that take JNI Version parameter, will the resulting JNIEnv only have those function table entries for that version, or the most recent one?
    It sounds safest to assume it implements only the version you requested, unless you call GetVersion first to determine the true version.
    > Does this actually mean they should use a va_list and the C calling convention, rather than JNICALL and explicit params (as in "ordinary" native methods)?
    The book makes this clear. You pass pointers to "ordinary" native methods, having the exact same prototype and implementation as if you used implicit linking rather than RegisterNatives.
    -slj-

  • Question using jni

    Hi,
    This is the first time I use jni and I encountered some problem when trying to accessing instance fields. My source code is as follows:
    java side:
    class C {
    int j;
    private native void f();
    static { System.loadLibrary("C"); }
    public static void main(String[] args)
    C c = new C();
    c.j = 5;
    System.out.println("Before calling: " + c.j);
    c.f();
    System.out.println("After calling: " + c.j);
    native (c) side:
    #include <stdio.h>
    #include "C.h"
    JNIEXPORT void JNICALL Java_C_f(JNIEnv *env, jobject obj)
    jfieldID fid;
    jclass cls = (*env)->GetObjectClass(env, obj);
    fid = (*env)->GetFieldID(env, cls, "j", "I");
    if (fid == 0) {
    return;
    printf("Before set: %d\n", (*env)->GetIntField(env, cls, fid));
    (*env)->SetIntField(env, cls, fid, 100);
    printf("After set: %d\n", (*env)->GetIntField(env, cls, fid));
    The programs compile and run smoothly, but the result is not what I expect. Please see the result below:
    jason1:~/jni/accessInstanceVar> make
    javac C.java
    javah -jni C
    gcc \
    -I/usr/lib/jdk1.1/include \
    -I/usr/lib/jdk1.1/include/linux \
    Java_C_f.c -c -o libC.o
    gcc -shared -o libC.so libC.o
    java C
    Before calling: 5
    Before set: 196653
    After set: 100
    After calling: 5
    I don't know why the value of the instance variable is not 5 when first accessed in the native function and why it is still 5 after the native function returns.
    Can someone help me? Thanks in advance!
    Yong

    It looks to me like you try to set a value of an instance variable like a static varibale.
    I think you need exatra information like the object which the instance variable like so:
    (*env)->SetIntField(env, obj, fid, 100);;
    instead of
    (*env)->SetIntField(env, cls, fid, 100);
    Hope this will help
    Joeseph.

  • Scale out question: how does instance name affect primary/secondary node

    Hi:
    OBIEE 11.1.1.6.4, Windows 2008
    On a test instance the following happened:
    1. Enterprise install of OBIEE 11g had problems
    2. Reinstalled OBIEE 11g, but the installer created an instance2
    3. All was well with this install
    4. Performed all necessary shared catalog and RPD steps
    5. On a second server, installed OBIEE 11g using the scale-out option
    6. On second server, this created an instance1 directory
    7. All components start up and we can log into OBIEE using either server1 or server2
    Question:
    Does OBIEE use the instance names in a scale-out? Our primary node is instance2 and the secondary node is instance1, though on a separate server. Will this cause a problem?
    Thanks for any help.

    Hello,
    This can be run on any of the replicas that the availability group participates in to return the primary instance:
    select primary_replica FROM sys.dm_hadr_name_id_map nim
    inner join sys.dm_hadr_availability_group_states ags
    on nim.ag_id = ags.group_id
    WHERE nim.ag_name = 'MyAvailabilityGroupNameHere'
    Sean Gallardy | Blog | Microsoft Certified Master

  • Question about final instance variables

    Hi, I recently have come across a situation that I realized I did not understand and I could not find the answer after a bit of googling and searching the forum so I thought I would quickly pose the question to the crowd. Basically I want to know if declaring a final instance variable and assigning it to an existing Object will make an immutable copy of that Object. For example:
    Dimension myDims;
    public void someMethod()
    myDims = new Dimension(320, 240);
    doSomething();
    public void doSomething()
    final myFinalDims = myDims;
    This is not real code (obviously) and I made it quickly just to get my point across. Basically my question is if I create an Anonymous Inner class within the doSomething() method that accesses the myFinalDims variable, will the inner class actually access the myDims variable (which could have its value changed before the inner class accesses the variable) or will it be accessing a copy of the myDims Object that will have the same value as when the final variable was declared and instantiated?

    Basically I want to know if declaring
    a final instance variable and assigning it to an
    existing Object will make an immutable copy of that
    Object. Big no. It will neither make a copy, nor will anything be immutable. Final just means that once the value or reference of the attribute or variable is set, it can't be altered.
    final StringBuffer sb = new StringBuffer();
    sb.append("!");still works.
    Your inner class will access the instance of Dimensions stored in myDims. There won't be any other instance.

  • A question about JNI references, persistence, and garbage collection

    I am writing a library to allow our Java developers to access C functions in our product. I want people on the Java side to be able to instantiate instances of a new object (on the C side), say "Map", and I want those objects to persist until they are destroyed on the Java side. I am thinking of creating a wrapper for the native methods, which stores an identifier for the instance of an object. When the C object is accessed, the identifier is passed to the C code which looks up the correct object in a table. I understand that if I use the NewGlobalReference call in JNI I can get objects to persist.
    When it is time for garbage collection I plan to override finalize() to call the C code and tell it to remove the Global Reference.
    Here's what I have in mind
    public class JMap() {
         private static int id;
         static {
              System.loadLibrary("libMap");
              /*Call C method which instantiates object and creates a GlobalReference
              which is stored in table. Returns ID for reference*/
              id = _init();
         public void setSize(int x, int y) {
              _setSize(id, x, y);
         public void finalize() {
              _finalize(id);
              super.finalize();
         private native int _init();
         /*calls DeleteGlobalReference for the reference matching this id*/
         private native void _finalize(int id);
         private native void _setSize(int id, int x, int y);
    }Is this the right thing to do? Have I understood the way JNI works with regard to GlobalReferences?
    Any comments, tips or pointers would be appreciated :)

    This probably should have been posted in the Native Methods sub-forum, I have reposted there:
    http://forum.java.sun.com/thread.jspa?threadID=657667
    Mods please delete this post :)

  • Trivial Lock Question - nested synchronized instance method call

    Hi there. I have a question surrounding the following code block:
            public synchronized void bow(Friend bower)
                System.out.format("%s: %s has bowed to me!%n",
                        this.name, bower.getName());
                bower.bowBack(this);
            public synchronized void bowBack(Friend bower)
                System.out.format("%s: %s has bowed back to me!%n",
                        this.name, bower.getName());
            }If the bow method is invoked by the currently executing thread that has obtained the lock on the current instance and the
    call "bower.bowBack()" is invoked, what happens? Is the lock released then obtained again by the current thread? or does it hold onto it since the method
    "bowBack" is called within the method "bow"?
    Thank you!
    Regards

    thank you as always mr. verdagen!
    regards

  • General Question About common Instance Names in Flash CS4 (AS3)

    I tried something interesting recently. I had code effecting an object with the instance name : object_mc.
    Now I added another object and gave it the same instance name.
    The result was, that the code only effected the most recent added object (no error).
    Is there a way in flash to have multiple objects with the same instance name all being affected by one piece of code?
    ~ Thanks for any thoughts, advice or facts. ~

    Advice: avoid it... if you want to control different instances, give them different instance names.
    It depends on what you mean by "one piece of code".  Directly using the instance name to target the movieclips will work as you have seen already... Last one added gets the attention.
    To use the instance name to take action is doable more along the lines of testing each movie to see if it has the name, but still, you would have to target each using a different means. 
    For the piece of code below I have some number of objects on the stage and I test to see if they have an instance name assigned (object_mc) that is shared by some of them, and I am able to move them if they do, but I cannot use the instance name to target each of them for action... in this case I use the getChildAt method.
    for(var i=0; i<this.numChildren; i++){
    if(this.getChildAt(i).name == "object_mc"){
      this.getChildAt(i).x += 200;
      object_mc.x += 25;  // only moves the last object added

  • Interesting naming question-Keyword: Factory, Instance

    Although I have written Java for a year, I still can't find this answer. What exactly means Factory, Instance in Java?
    Why use these two words in some classes, say SAX, JCE KeyGeneratorFactory, KeyGenerator? What implies relation between two class from naming?

    Factory relates to the Factory design pattern as described by the Gang of Four (GOF). Check out any design patterns resource for this pattern to get a more complete answer.
    Essentially, though, a Factory constructs an instance of a class for you. The exact class returned is determined by the factory (for example, DocumentBuilderFactory uses a system property to get the name of the class to instantiate).
    Another example is javax.swing.BorderFactory which simply instantiates TitledBorder, EmptyBorder etc instances based on the method you called.
    Hope this helps.

  • Simple question, make symbol/instance "transperent"

    Hi guys.
    My problem is quite simple but I havent found a way to solve it yet. I want to make my symbol/instances (dont know the difference) transperent. And, when I have a button, I want only the button itself to be clickable not a bit of the white space around.
    When I draw something directly in Flash it seems to work fine just as I want it, but I work in paint for the moment and will be using Photoshop too, so then I cant use just Flash's tools.
    //Sebastian

    When using Photoshop, for example, save your transparent image as a .psd and import it into Flash. I've never had success with copy/paste into flash for transparent images.
    Now as far as clickable areas go, if you're using a transparent bitmap for a button skin -- and it has transparent areas you don't want clicked, you can create a mask within flash to 'hide' the transparent areas.
    HTH,
    -Ted

  • Basic question about v_$instance vs. v$instance.

    I'm new to Oracle and am wondering if anyone can tell me who the owner of v$instance is? Is it SYS? I know SYS is the owner of v_$instance.
    Thanks,
    Greg

    v$instance is a public synonym for V_$INSTANCE

  • Storing instance-related data on C side.

    Hello!
    I have a question on JNI:
    In my class all methods are native. I need to store some instance-related data for my processing.
    Is there a way to do this with less overhead than by placing this data to Java class and accessing them through JNI?
    I don't need to access to this fields from Java, only from C.
    I.e. the solution that I have now is:
    Java:
    public class stream {
        private int handle = -1;
        public native int open(byte[] szFilename, int mode);
        public native int read(byte[] buffer, int offset, int length);
    C:
    JNIEXPORT jint JNICALL stream_open (JNIEnv *env , jobject obj , jbyteArray szFilename, jint mode) {
      jclass cls = (*env)->GetObjectClass(env, obj);
      jfieldID fid;
      jint handle;
      fid = (*env)->GetFieldID(env, cls, "handle", "I");
      if (fid == 0)
        return;
      handle = <open>
      (*env)->SetIntField(env, cls, fid, handle);
    JNIEXPORT jint JNICALL stream_read (JNIEnv *env, jclass cls, jbyteArray buffer, jint offset, jint length)  {
      jclass cls = (*env)->GetObjectClass(env, obj);
      jfieldID fid;
      jint handle;
      fid = (*env)->GetFieldID(env, cls, "handle", "I");
      if (fid == 0)
        return;
      handle = (*env)->GetIntField(env, cls, fid);
      ... (perform read)
    Is it possible to make this more effective, without having 'int handle' in Java? Certainly, it should be different for each instance.
    Thank you in advance
    Sergey

    Your native code is just subroutines, and "normally" data kept around is either local to the subroutine (and disappears between calls), or is global (and so not instance data).
    What is not clear from your description is whether you are talking about a) java "instances" for which you want to hold extra data on the C side, or b) you simply have a bunch of C data that you would like to keep around - instances perhaps of some C++ class.
    If it is the former, then the likely options are
    o Pass the data back to the java side, and hold it in java objects.
    o Allocate space on the C side, and pass a pointer to the java object to hold it. (If you do this, save the pointer as a "long".)
    o Allocate the space on the C side, setting up some sort of lookup structure, and holding a key in each java object.
    One thing to remember is that you need a way to cleanly dispose of C-side data.

  • Object reference not set to an instance of an object. Unable to finish the SQL 2012 installation on a VM Machine

    Hi, My name is Leonard and I am studying SQL. I have downloaded the newest MS SQL 2012 and also MS 2012 Hyper-V. I have set a MS 2012 Hyper-V on a laptop with AMD Turion 64 X2 and 3G of RAM (Planing
    to add more to max at 8G).
    Following the instructions in the free online
    Administering Microsoft SQL Server 2012 Databases” Training Kit, I have set 6 virtual machines as instructed in the Training Kit. While the installation of the MS Server Core 2008 R2 SP1 completed with no
    problem, the same cannot be said for the SQL Server 2012 installation. I have encountered an error that I have not seen anyone address in any of the SQL web forums.
    After running the unattended setup instruction (Setup.exe /qs /ACTION=Install /FEATURES=SQLEngine /INSTANCENAME=MSSQLSERVER
    /SQLSVCACCOUNT="Njowa\Pa$$worD>" /SQLSVCPASSWORD=" Pa$$worD” /SQLSYSADMINACCOUNTS="Njowa\lenny#4!@" /AGTSVCACCOUNT="NT AUTHORITY\Network Service"
     /IACCEPTSQLSERVERLICENSETERMS) this is what I get after a series SQL setup
     initiation windows popups then disappears.
    The following error occurred:
    Object reference not set to an instance of an object.
    Error result: -2147467261
    Result facility Code: 0
    Result error Code: 16387
    Please review the summary.txt log for further details
    My question is: What instance of an object is not properly initialize in the Setup instructions

    Hello,
    Please note that SQL Server requires at least 1 GB of RAM. The operating system (Windows Server) requires 2 GB of RAM (recommended) or 512 MB (minimum). This means any virtual machine that will receive the installation of a SQL Server instance requires 1.5
    or 2 GB at least.
    The behavior of SQL Server setup tells me that the virtual machine does not have enough memory assigned or .NET Framework 3.5 was not enable on Control Panel->Program
    and Features before trying to install SQL Server.
    The following thread is about another possible cause of this error:
    http://social.msdn.microsoft.com/Forums/mr-IN/sqlsetupandupgrade/thread/575d3025-69f5-4152-a473-44496b008811
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Multiple production instances - KScope follow up

    Had this posted on Network 54 and it was recommended that I post here as well.
    During one of the lunch and learn sessions at KScope I texted in a question about multiple instances in production. It seemed there was some confusion to the question so I thought expanding the question with additional details here may provoke some additional conversation on the topic.
    We are currently running a single essbase instance with active - passive clustering in production on 11.1.2.1 (considering 11.1.2.3 for next year). For example purposes lets say we have two business areas sharing the instance each with 50 applications for a total of 100 applications. Things run very smoothly most of the time, but from time to time during peak usages the single threaded nature of the security file can slow things down. My thought was to run two instances of Essbase, one for each business area, one active on server A and one active on server B. They would each have there own failover to the other server.
    Current Set-up
    Server A
    Active
    Instance 1
    100 applications
    Server B
    Passive
    Instance 1
    Proposed Setup
    Server A
    Instance 1 active - 50 applications
    Instance 2 passive
    Server B
    Instance 1 passive
    Instance 2 active - 50 applications
    I have seen that you can setup multiple instances on a server, but have also seen that it is not recomended for production. Are they considering this scenario when they do not recommend it or are there other reasons. I am fine if both instances fail to the same server as we run all applications on one server now and have plenty of memory. Also, we would have separate file systems and a separate port for the second instance (our end users do not know the port bases on their log in today so that will not be an issue). Are there any concerns with this approach, has anyone else tried it? We have successfully done this in our development region, but that does not have the usage on it that production has. It also seems a waste to have all the processors and memory sitting on server B not doing anything - we are paying for it why not use it.
    Some additional information that was requested.
    This is in addition to DR and having failover is required based on internal audit/IT standards.
    We have a NAS device and understand that is still a single point of failure and is likely a bottleneck, which is why we archive any modified databases each night along with packaging up rules and calc scripts.
    The servers are UNIX with 48 cores and 256+ Gig of Ram.
    About half or more of the databases require write back.
    Thanks Andy

    We have implemented similar solutions to take advantage of a server that otherwise be redundant for the majority of the time and it does work well, I have not personally done this type of configuration on unix using OPMN but have on windows using failover clusters, I feel OPMN is a bit poor in terms of management and lacks functionality so maybe worth considering Oracle clusterware depending on the flavour of Unix.
    You could also look at look at virtualisation options as an alternative.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How do I customize Adobe Acrobat Standard DC or Adobe Acrobat Pro DC to do what I'd like?  Actually this a multiple-question inquiry.

    Note, I was unable to find a "How TO", Tutorial, or FAQ relevant to the following questions.
    For instance, how do I easily append to an existing PDF with minimum clicks (which I could do with an earlier version of Acrobat Standard)?
    I'm using a 30-day trial of Adobe Acrobat Pro DC to scan documents and in certain situations, append to existing PDFs.
    I'd prefer to trial the Adobe Acrobat Standard vs. Pro DC because that's what I intend to purchase.  I'd prefer to not get accustomed to Pro if Standard is very different.
    1.  After selecting Edit > Preferences and specifying certain defaults, most take effect as suspected but some do not, like the one's I'm going to elaborate on below.  Why?
    2. Alternatively, is there a Tool or a way to create a local customized Profile and default to that Profile to avoid having to repeat the following steps?
       This should not be confused with the online Profile (or Communities Profile) whereby one states one's Name etc.
    File
    > Create
       > PDF from scanner
         > Custom scan
           > Color Mode: Black and White
           > Append to existing file
             > Browse
               > Select file
                 > Scan
    This is a cumbersome task to repeat each time I'm ready to scan.  Using an earlier version of Acrobat Standard, I'd simply double-click the PDF I wished to append to,
    Acrobat would default to the appropriate scanner, and know that I wished to append to an existing file without me having to select that option.  Presently it doesn't appear to be that easy/simple.
    Perhaps it is (or can be with guidance).  Please assist.
    3. Please find attached the following snapshots/images... CORRECTION, IF ADOBE SUPPORT CONTACTS ME ABOUT THIS, I'LL GLADLY FORWARD SCREENSHOTS.
       Meaning, there does not appear to be a way to include screenshots on Forums.
    3a See Error.  Is there a way to get a more accurate description of the error (i.e., turn on debugging etc.)?
    3b When Creating a PDF, the prompts still seen after clicking "Configure Presets" and changing Color Mode from AutoDetect to Black and White.  Why?
    3c Custom Scan Input, where I changed Color Mode from AutoDetect to Black and White and why I must also tell Acrobat to append AND to browse to a pre-defined default location?
    4. Must I be "Logged in" to use the product?  The first time launching it, I was prompted to login using the credentials used to create the account and download the product.  Now when using the product it appears to be automatically "Logged in" or online.  I would prefer to use it in an "offline mode" if there is such a thing.
    5. Once the product is purchased, what are my support options?  Can questions be answered or issues resolved with a phone call or are they limited to the Acrobat Forum(s) and/or Adobe Communities?  Even after clicking "Ready to contact us?  Start here." I'm only given the Forum option (over and over) vs. Chat vs. Email Support etc.
    If I've posted these inquiries to the wrong Forum or Discussion, if prudent, please collectively relocate them.  Regardless, please advise.  Thanks!

    uninstall all acrobat/reader versions and retry installing.
    or check your log files for more specific help, Troubleshoot install issues with log files | CS5, CS5.5, CS6

Maybe you are looking for

  • Installing an existing CS5 software on a new computer, without CD drive

    I am going to install ps5 on a new computer, but it is no CD drive on the new. I was thinking to download CS5 from Adobe, but I cannot find it. Anyone who knows how to do it?

  • Links are not working well, some do and other don't!

    Because I want to have url's like www.name.nl/products/productx.html, www.name.nl/organization/personal.html  etc. I made for each map a different little website. I made the menu manually and for each menu item I made links like: http://www.name.nl/p

  • I've changed the exch. rate, but the Amount in Local Curr.EUR isn't changed

    Hi All, I've posted a bank document in USD dollars. In FB03 I can see for that document the  "Amount in document currency" (USD $) and the Amount in Local Currency (EUR). Later I've set the "exchange rate" in S_BCE_68000174. If i turn to display that

  • Can't Change Account Full Name

    In System Prefs > Users & Groups, The text entry field to change the User's Full Name is no longer there.  Does anyone know how to change the User's Full Name? in OS 10.10? At the moment, my user full name is "Philip's MacPro".  Before the upgrade it

  • If we have any self respect, we should boycott Nok...

    Nokia is dumping defective phones in India (like the Lumia 800) because a) India has no laws  b) They view Indians with contempt. I have had a Lumia 800 for nearly 2 months. It never worked, has been sent for repairs twice, and I have been told 'no r