Are DLL methods called as instance or static methods from Java ?

Hi,
I have only a small question.
When I call a C++ DLL method from Java using JNI, do I instantiate it like an object method or is it called as a static method ?
I am asking you this because I will use servlets (Java 1.2.2) to call a DLL. These servlets may run concurrently in any moment, and I pass some data to this DLL. I want to know if there is any possibility of this data becoming corrupt, because of one concurrent servlet rewriting the data another servlet has passed.
Thanks and regards.

The question is not specific enough.
Methods in C/C++ can be qualified with the following forms:
-global (C/C++)
-static member(C++ class method)
-instance member(C++ class method)
Since you didn't provide your code I couldn't possible determine which of the above you are using, but presumably you know.
On the other hand a java native method is either static or non-static depending on how you defined it in the class. Once again without the code there is no way to say and presumably you already know this.
The context of the methods is the same context that a similar servlet method has. But naturally in C/C++ is is easy to circumvent the context - for example by using a global variable.
Data in C/C++ can always become corrupt and in the vast (all?) cases it is because something is wrong in the C/C++ code. Like a pointer that is not initialized, or a pointer used after it is free'd. Or writing past the end of a buffer, or writing before the beginning of a buffer.

Similar Messages

  • Memory, instance vs static methods?

    Well, have memory problems again.
    Question: what is more efficient: using one single instance of a class all over the place, or put static methods in this class, so no instance is needed. I'm guessing it doesn't make a lot of difference, but who knows, I could be wrong...

    Well, it appears that they don't affect runtime memory as long as the class is not needed. I guess the classloader will only load the class onto the heap from jar.
    The application start about 100 KB of memory is available (and that is about all of the heap). While creating more objects, memory usage increases drasticly. Definantly more than only the data stored in the classes, so it must also be loading the bytecode at that time.
    I still have some tricks up my sleeve, so I hope I can work it out...

  • Call ODBC Data Source Administrator dialog from java code

    Hai all
    Is it possible to call "ODBC Data Source Administrator dialog " using java code.
    Tell me whether it is possible or not?
    If yes then kindly give the code please.

    try{
    Runtime.getRuntime().exec("odbcad32.exe");
    } catch(Exception e){
    e.printStackTrace();
    }or
    try{
    ProcessBuilder pb = new ProcessBuilder("odbcad32.exe");
    pb.start();
    }catch(IOException e){
      ioe.printStackTrace();
    }make sure path variable has %SystemRoot%\system32; value.
    guess both have to work... :)
    NOTE: It is OS Dependent (specially for MS WINDOWS based OS's) & the second method would work for Jdk versions of 5.0 & above..
    Hop this would be of some help :)
    REGARDS,
    RaHuL

  • How to call a exe or bat file from java program

    hi,
    i actually want to know that how to call a exe or bat file from program so that i can run them parallely.

    Try this :
    String strCmd = "myFile.bat";
    try
         Runtime rTime = Runtime.getRuntime();
         Process process = rTime.exec(strCmd);
         InputStream p_in = process.getInputStream();
         OutputStream p_out = process.getOutputStream();
         InputStream p_err = process.getErrorStream();
         p_in.close();
         p_out.close();
         p_err.close();
    catch(Exception e) {
         throw new Exception("Unable to start, "+strCmd);
    }

  • How to call PL-SQL script/stored procedure from Java?

    Assume I want to call a PL-SQL stored procedure from external Java program.
    How can I do this?
    Is there a simple "Hello world" example for this?
    Peter

    This forum is for Oracle only not for java
    Ug

  • Are there any APIs to access user personalization data from java

    Hi gurus,
    We want to access personalization data for a user from java using API. This includes user mapping also.
    If you are aware of any api please let me know.
    Thanks in advance.
    Regards,
      Pratik Thakkar

    Hi Pratik,
    You can also retrieve a system object and get the user mapping for the system:
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
    env.put(Context.SECURITY_PRINCIPAL, request.getUser());
    env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
    iCtx = new InitialContext(env);
    ISystem pcdSys =(ISystem)iCtx.lookup(sysId);
    ISystemUserMappingData um = pcdSys.getUserMappingData(request.getUser());
    From this object you can get the user, password and other properties.
    As for personalized values of iView attributes, you can an environmental value before create the initial context to indicate to return personalized value, as follows:
    env.put(IPcdContext.PCD_PERSONALIZATION_PRINCIPAL, request.getUser());
    Hope this helps.
    Daniel

  • Calling inactive version of ABAP object from Java

    Hello,
    When I call an ABAP object from Java Program which version of ABAP object is called inactive or active ?
    Is there a mechanism to call the current inactive version or any other previous inactive /active versions ?
    Regards,
    Tarun

    Only the "active" version of ABAP code is active and runnable.
    You cannot run inactive versions. Like you have to compile a .java file to a .class file o make it runnable in the JVM.

  • Calling an EJB deployed in OC4J from Java Stored Proc in Oracle

    Hello!
    Trying to make a call to an EJB deployed in OCJ4 from a oracle java stored proc. After loaded orion.jar and crimson.jar lib into SCOTT schema, I can't get the JNDI Context working because of this error:
    ============================================
    javax.naming.NoInitialContextException: Cannot instantiate class:
    com.evermind.server.ApplicationClientInitialContextFactory. Root exception is
    java.lang.ClassNotFoundException:
    com/evermind/server/ApplicationClientInitialContextFactory
    at java.lang.Class.forName0(Class.java)
    at java.lang.Class.forName(Class.java)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:45)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java)
    at javax.naming.InitialContext.init(InitialContext.java)
    at javax.naming.InitialContext.<init>(InitialContext.java)
    ===============================
    I did load the java with "loadjava" with on time with the "resolve" option and time time no option and still no working.
    Here is the EJB client code:
    =======================================
    import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    import com.evermind.server.ApplicationClientInitialContextFactory;
    class EmpRemoteCall {
    public static void main(String[] args) {
    System.out.println(getEmpName());
    public static String getEmpName() {
    String ejbUrl = "java:comp/env/ejb/Emp";
    String username = "admin";
    String password = "admin";
    Hashtable environment = new Hashtable();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationClientInitialContextFactory");
    environment.put(Context.PROVIDER_URL, "ormi://127.0.0.1/testemp");
    environment.put(Context.SECURITY_PRINCIPAL, username);
    environment.put(Context.SECURITY_CREDENTIALS, password);
    //environment.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    //environment.put(javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    com.kboum.sertir.essais.EmpHome homeInterface = null;
    try {
    Class.forName("com.evermind.server.ApplicationClientInitialContextFactory", true, ClassLoader.getSystemClassLoader());
    System.out.println("Creating an initial context");
    Context ic = new InitialContext(environment);
    System.out.println("Looking for the EJB published as 'java:comp/env/ejb/Emp'");
    homeInterface = (com.kboum.sertir.essais.EmpHome) ic.lookup(ejbUrl);
    catch (CommunicationException e) {
    System.out.println("Unable to connect: " + ejbUrl);
    e.printStackTrace();
    //System.exit(1);
    catch (NamingException e) {
    System.out.println("Exception occurred!");
    System.out.println("Cause: This may be an unknown URL, or some" +
    " classes required by the EJB are missing from your classpath.");
    System.out.println("Suggestion: Check the components of the URL," +
    " and make sure your project includes a library containing the" +
    " EJB .jar files generated by the deployment utility.");
    e.printStackTrace();
    //System.exit(1);
    catch (ClassNotFoundException e) {
    System.out.println("Unable to connect: " + ejbUrl);
    e.printStackTrace();
    //System.exit(1);
    try {
    System.out.println("Creating a new EJB instance");
    com.kboum.sertir.essais.Emp remoteInterface = homeInterface.findByPrimaryKey(Integer.valueOf("7369"));
    System.out.println(remoteInterface.getENAME());
    System.out.println(remoteInterface.getSAL());
    remoteInterface.setSAL(2);
    System.out.println(remoteInterface.getSAL());
    return remoteInterface.getENAME();
    catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    return "error";
    null

    What I did to solve this problem was to
    create a simple RMI remote object that
    resides outside the database JVM and that
    serves as a proxy EJB client for your java
    stored procedure. The stored procedure can
    invoke a method on the remote RMI object
    which then looks up the EJBean's home
    interface and invokes the relevant method on
    the bean's remote interface, and relays any
    return values back to the java stored
    procedure.
    Hope this helps,
    Avi.
    null

  • Static methods, what for?

    What are static methods for? is there something that is not possible through methods associated with instances (non-static methods) ?

    There are many examples of static mehods in the Java API. For example the Math or the System class. All methods in this classes are static. So you dont have to instantiate the system class. In fact it is even not possible to instantiate the System class. System is final and all Constructors are private.
    Another use for static methods is the access to private static variables.

  • Static method and threads?

    I have a question regarding "static". for example, I have the following code
    class Test{
    public int i=0;
    public static calculateInt(){
    ....some operations on i;
    if two processes attempt to call Test.calculateInt() at the same time. What will the effects be? shall these two calls be implemented totally independent? each call holds it own "i" for calculation. OR there will be operation conflicit on i.
    what if I change "public i" to :private i", the same effects?

    You can't operate on i in a static method, since i is an instance variable.
    If you make i static, then you can operate on it in a static method. In that case, all threads will share a single i--there's only one i for the whole class, and threads don't change that. Making it private won't change that.
    If you make the method into an instance (non-static) method, then any threads operating on the same instance will share the same i, regardless of whether it's public or private. Different threads operating on different instances will each have their own i.
    Java's Thread Tutorial
    JavaWorld: Introduction to Java threads
    IBM: Introduction to Java threads
    Google: java+threads+tutorial
    Also check out http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html

  • Static Method Call

    Hi,
    I had a private method which is called in a number of different places in my class. I have changed this method to be a public static method, will this effect the other areas in this class which are calling this method?
    Thanks
    Dude

    Did you have to change any fields from instance to static? If not, then the method probably did not need to be an instance method and you should be Ok. You should just make sure that what the method is doing is not designed to update / manipulate an instance of the class.

  • How do I 'call' external instance methods?

    I want to send a message from a Controller to another Class  to execute a method.  Inside the controller, I typed my message:     
                    [[MemoryContent]  PopulateMemory];
    What I think I am doing here is telling it to go to the MemoryContent class and execute the method called PopulateMemory.  The compiler insists that I make PopulateMemory into a class method.  But when I do that, I cannot deal with the instance methods and instance variables that I need.  What am I missing?

    Assuming you are following recommended Cocoa naming conventions, the fact that MemoryContent has an initial cap means it is a class, not an instance of a class. So the compiler error is correct. If you want to use an instance method, first create an instance of the class, then call the method on the instance.
    Your method name PopulateMemory should probably not have an initial cap.
    So you would typically see something like this.
    MemoryContent *memoryContent = [[MemoryContent alloc] init];
    [memoryContent populateMemory];
    Of course if the class instance already exists, don't create another one. Instead get a reference to the existing instance.

  • Static methods vs instant methods

    hi to all abap gurus
    thanks in advance
    all of the objects in the class can acess its its static attributes . and if u change the static attribute in an  object the change is visible in all other objects in the calsssss.
    can u pls expain this and tell the diffrence bewteen static and instance metod s?

    Hi,
    <b>Instance Method</b>
    You can declare instance methods by using the METHODS statement. They play a very important role as they can access all of the attributes of a class and can trigger all of the events of the class.
    <b>Static Methods</b>
    You can declare static methods by using the CLASS-METHODS statement. They are important and can only access static attributes and trigger static events.
    <b>STATIC METHODS</b>
    CAN ONLY USE STATIC COMPONENTS IN THEIR IMPLEMENTATION PART
    CAN BE CALLED USING THE CLASS
    Static methods (also referred to as class methods) are called using CALL METHOD <classname>=><class_method>.
    If you are calling a static method from within the class, you can omit the class name.
    You access static attributes using <classname>=><class_attribute>
    Regards,
    Padmam.

  • Static methods in interfaces

    Java cognoscenti,
    Anyone know why I can't declare a method as static in an interface, but I can in an abstract class. Surely, semantically it's the same - defering the implementation of a static method, not an abstract class and an interface. By the way, I'm using JDK 1.2.2 if that makes a difference

    No, it's not the same. You are not "defering the
    implementation of a static method" because static
    methods are never polymorphic.
    Static methods cannot be abstract for this reason, and
    only abstract methods are allowed in interfaces.I didnt't know that. I thought that - because you can override static methods and you can call them onto an actual instance the method binding would be done at run-time, not at compile-time. So I was trying to prove you wrong, but you are correct !
    A short summary of what I've learnt so far:
    - interfaces cannot contain static methods
    - abstract classes cannot contain abstract static methods
    - static methods can be overriden, but they are not polymorphic; this means that the compiler decides which method to call at compile-time.
    /* output
    SuperClass.someMethod()
    SubClass.someMethod()
    SuperClass.someMethod()
    SuperClass.someMethod()
    SubClass.someMethod()
    SubClass.someMethod()
    SuperClass.someMethod()
    public class Test {
      public final static void main(String[] args) {
          // output: SuperClass.someMethod()
          new SuperClass().someMethod();
          // output: SubClass.someMethod()
          new SubClass().someMethod();
          // output: 2x SuperClass.someMethod()
          SuperClass someClass1 = new SubClass();
          someClass1.someMethod();
          showSuper(someClass1);
          // output: 2x SubClass.someMethod()
          SubClass someClass2 = new SubClass();
          someClass2.someMethod();
          showSub(someClass2);
          showSuper(someClass2); // SuperClass.someMethod()
      public final static void showSuper(SuperClass c) {
            c.someMethod();
      public final static void showSub(SubClass c) {
            c.someMethod();
    class SuperClass {
      public static void someMethod() {
        System.out.println("SuperClass.someMethod()");
    class SubClass extends SuperClass {
      public static void someMethod() {
        System.out.println("SubClass.someMethod()");

  • Static methods in interface (Yes, once again!)

    I know there has been many questions about why static methods in interfaces are not allowed. I know it is forbidden by the JLS. But does anyone know the exact reason for this? Is it just a design issue or are there technical difficulties with allowing it?
    I can't think of any reason that it should be impossible to allow static methods in interfaces. I don't even think it would be very difficult to do. More importantly, it could probably be done without breaking existing code and existing JVMs (not too sure about the last one).
    So once again: Was the choice of not allowing static methods in interfaces a design choice or a technical choice?

    A better example of what you are suggesting is surely ...
    interface i {
        static void one();
    class a implements i {
        static void one() {
            // do something
    class b implements i {
        static void one() {
            // do something else
    }What would be the point of ever doing this?
    You cant call i.one() as the method doesn't exist without an instance of an implementing class.
    To actually ever be able to use that method you would effectively be casting an INSTANCE of a or b -> i. If you have an instance of an a or b then there is absolutely no reason for that method to be static.
    If you wanted to implement some sort of class (ie static) behaviour then class a could call its own internal static method from within the 'one' method.
    To get right to the point ... there isn't one. If it gets added to the language (and I can't see it in my wildest dreams) then Sun have lost their marbles, surely?
    Unless someone can give a good example of when it might be correct and useful to do so? I can't even see how it would be a convenience as it is completely unusable, no?

Maybe you are looking for