I want to execute other java thread in the JNI.

Hi!
I would like to execute other java native thread concurrently in the Java Native Interface.
When a Java thread called a native thread to use java native interface, Java thread is blocking for processing native thread.
So, other java threads don't execute because they are blocking.
Why do these problems occur at JVM(personal basis profile:CVM)?
I hope you explain this reason in detail.
Regard.
Message was edited by:
peeppeep

Cross post
http://forum.java.sun.com/thread.jspa?threadID=786857&messageID=4471999#4471999

Similar Messages

  • I want to call External Java class from the PL/SQL

    Hi,
    I am using Oracle Apps R11i (11.5.7), I wanted to call external Java class from the PL/SQL. This external Java class is residing in another application server.
    How do I do this.
    I know one way. Develop C routine in Oracle Apps to call external java class and call this C routine from the PL/SQL.
    Is there any simple method available? or any other method?
    Thanks in advance.
    -Venkat

    First of all, this is a Java application you're talking about, right (i.e. it has a main() function)? It's not just a class that you're trying to instantiate is it? If it's an application, you obviously have to start a new virtual machine to run it (rather than using the virtual machine built into the database like stored java). I'm a little leary of your mention of an "application server" as this would more commonly mean that a virtual machine is already over there running with access to this class. In which case, you'd typically interface with SOAP or some other RPC API.
    All that aside, as long as you have physical disc access (through NFS or whatever) to the class file, you could use a java wrapper class with a system call to do this. In fact, there is a thread in just the last day or so on this very forum that has the code to do just that (see " Invoking OS Commands from PL/SQL"). However, it's worth noting that the virtual machine will be running on the database server in this case and not the application server.

  • How to execute a java application once the server starts

    I have created a java application which executes correctly. I want this application to execute everytime I start my server. I have modified my web.xml as shown below
    <servlet>
    <servlet-name>SendEmail</servlet-name>
    <servlet-class>
    com.allcorp.alliance.tdocs.servlets.SendEmail</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    <load-on-startup>1</load-on-startup>
    </init-param>
    </servlet>
    I have extended the class with HttpServlet. When I start the server, I get the message saying the class is being initializing but it does not execute. I want the application to execute. Any idea what I need to do.

    BalusC wrote:
    Implement ServletContextListener and run the appplication on creation of the ServletContext.Well i understand implementation of ServletContextListener and by overiding contextInitialized(ServletContextEvent se) accordingly can solve the problem.
    but you need to consider two cases here first
    1).ServletContextListener is not supported by all container especially the minor onces which does not support Servlet 2.3 specification.
    2).OP does not have any idea of how to use a Servlet first if you can see he had written his intialization code in the main method.Now how can you expect him to create a listener..... :)
    I hope there are no hard issues on what i said this time.
    *@OP*
    My friend the bad news is that you need to spend bit of time learning about servlets.U'd not be writing intialization code inside a main rather you'd be doing it inside public void init(ServletConfig config) method.
    by making <load-on-startup><!--value</load-on-startup> in web.xml enables Servlet container to call init method at the time of deployment of the web application else where it'd call the init method whenever servlet encounters first request from a client.
    package com.allcorp.alliance.tdocs.servlets;
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import javax.activation.*;
    * @author ssa3z
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class SendEmail extends HttpServlet{
    public void init(ServletConfig config) {
        // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
        String to = "[email protected]";
        String from = "[email protected]";
        // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
        String host = "smtp.allstate.com";
        // Create properties, get Session
        Properties props = new Properties();
       // If using static Transport.send(),
      // need to specify which host to send it to
      props.put("mail.smtp.host", host);
      // To see what is going on behind the scene
      props.put("mail.debug", "true");
      Session session = Session.getInstance(props);
      try {
         // Instantiatee a message
         Message msg = new MimeMessage(session);
         //Set message attributes
         msg.setFrom(new InternetAddress(from));
         InternetAddress[] address = {new InternetAddress(to)};
         msg.setRecipients(Message.RecipientType.TO, address);
         msg.setSubject("Test E-Mail through Java");
         msg.setSentDate(new Date());
         // Set message content
         msg.setText("This is a test of sending a " +"plain text e-mail through Java.\n" +"Here is line 2.");
         //Send the message
         Transport.send(msg);
      }catch (MessagingException mex) {
        mex.printStackTrace();
    } Hope this might help :)
    REGARDS,
    RaHuL

  • Java Logger incrementing thread ids for a thread spawnned via JNI

    Hi all,
    I have a Java Logger object that I am passing to a JNI dll written in C++.
    If I spawn a thread from the JNI dll and log from that thread, the thread id in the log file increments for each log entry.
    To test this I wrote an infinite loop on the thread to make sure that the logging originated from a single thread. The thread id keeps incrementing in the log and the memory usage of the process increases too. However, the thread count in Task Manager does not increase.
    I will let the process run overnight to determine if the thread id will overflow or if an out of memory exception occurs.
    Has anyone else seen this behavior? Does anyone know what I might be doing wrong? I'm using jre 1.5.1.
    Thanks,
    William

    (1)
    has anybody ever tried to use a native library from
    JNI, when the library (Windows DLL) is not thread safe?
    Now we want many Java clients.
    That would mean each client makes its calls
    to the library in its own thread. Because the library
    is not thread safe, this would cause problems.Right. And therefore you have to encapsulate the DLL behind a properly synchronized interface class.
    Now the details of how you have to do that depends: (a) does the DLL contain state information other than TLS? (b) do you know which methods are not thread-safe?
    Depending on (a), (b) two extremes are both possible:
    One extreme would be to get an instance of the interface to the DLL from a factory method you'll have to write, where the factory method will block until it can give you "the DLL". Every client thread would obtain "the DLL", then use it, then release it. That would make the whole thing a "client-driven" "dedicated" server. If a client forgets to release the DLL, everybody else is going to be locked out. :-(
    The other extreme would be just to mirror the DLL methods, and mark the relevant ones as synchronized. That should be doable if (a) is false, and (b) is true.
    (2)
    Now we discussed to load the library several times -
    separately for each client (for each thread).
    Is this possible at all? How can we do that?
    And do you think we can solve the problem in this
    way?The DLL is going to be mapped into the process address space on first usage. More Java threads just means adding more references to the same DLL instance.
    That would not result in thread-safe behavior.

  • Batch prog to execute remote java program

    hi all
    i have one batch file which executes the local java program ....
    but i want to execute a java program in a remote machine....
    how do i do this..? kindly help

    Well this is what I do in Windows (I use XP but it works in others):
    First you have to make sure all the class files are in the same folder (duh)
    Then you copy your java.exe from your jre folder into the folder with all your class files.
    Finally, you create a shortcut to java.exe and add your class name to the command line on the shortcut.
    Now all you have to do is double click on the shortcut and your program runs. Sure it's not that pretty but it works.

  • A blocking problem of java thread.

    Hi!
    I would like to execute native thread concurrently in the Java Native Interface.
    When a Java thread called a native thread to use java native interface, Java thread is blocking for processing native thread.
    So, other java threads don't execute because they are blocking.
    Why do these problems occur at JVM(personal basis profile:CVM)?
    Regard.
    Message was edited by:
    peeppeep

    you need to explaing the problem more clearly, maybe post the code?

  • Multiple java threads in a JVM created by the invocation interface

    Hi,
    I have a certain application APP that calls functions of a C library. One of these functions creates a JVM through the invocation interface. In the JVM I create some other threads and a Swing GUI. From the java "main" thread as well as the other threads (including the Swing event dispatcher thread) I need to call dll functions through native java methods. The latter indirectly (through another dll) invoke functions of an API of application APP.
    I have problems when making calls from the java threads to the java native library. In some cases everything works well i.e., I'm able to make calls to the java native library from both the "main" java thread and the other threads. In other cases a crash occurs when attempting to access the native library from any threads but the "main" thread.
    Can anyone help me on this? Is there any requirement that only the main java thread makes callbacks to C code?
    Thanks.

    > why later sets of java application is taking longer?
    Probably because of CPU usage.  But could be memory.
    >Can I do something here so that later sets of apps also completes in 3 mins
    You tune the task, the complete task, to the box.  That means you must understand in detail what is taking time and then architect that to make the best use of the available CPUs and memory (and other resources as used by the task.)

  • Can I package and call a java object in the swf? (on the client)

    Hello,
    Can I package and call/execute a java object within the
    swf/adobe flash player?
    I want to embed a java object in my swf, and then whne the
    swf executes have it call the java object......
    E.

    ..... there are few instances where it would be nice to
    develope a single java object that can be used on the server and
    the client..... let's say for the case of server side validation,
    that could also be used by the client application for validation,
    instead of having to maintain 2 sets of validation logic in two
    different languages (java and AS).....

  • How to execute a procedure depending on the result of a query?

    Hello, I'm new in ODI.
    I want to execute a procedure depending on the result of a query Oracle table.
    We have a Oracle Table whit a column that contains two possibles values.
    I want read the table, row by row, and depending on this value, execute a Procedure or execute another.
    How can i do?

    what you need to do is
    1. create a variable which "new_var2" which has the count of the number of rows you want to process. must be data type numeric.
    2. copy "new_var2" to the package screen.
    3. duplicate the "new_var2" on the package screen and evaluate the variable and test for "> 0" zero, call it "new_var2_E"
    3. create a new odi variable "new_var1" with a refresh of "select field1 fom (select field1,rownum as rownumber from tablex) where rownumber = #new_var2" in the relevant schema and technology.
    4. copy "new_var1" into your package (some where in the flow)
    5. right click the "new_var1" variable in you package screen and you should get the option duplicate step (click on that)
    6. select the the duplicate "new_var1" on the package screen and correct the the name to something meaning full to you "new_var1_E", also change the "type" to "evaluate variable" then you should see a "value" box. enter one of the values you want to test in the box (remember do not put in quotes ' )
    7. now back on the package screen join the "new_var1" to the "new_var1_E" with an OK line
    8 you now join "new_var2" to "new_var2_E" with OK
    9 you join "new_var2_E" to "new_var1"
    10. you then join the "new_var1_E" with an OK or a KO line to the relevant procedure.
    12. you need to duplicate "new_var2" in the package screen one more time this time and call it "new_var2_D" set the type to evaluate and then select the increment of -1
    13. the relevant procedure to "new_var2_D" with an OK
    14. join the "new_var2_D" to the "new_var2_E" with an OK
    15. this should close off the loop now the exit point is "new_var2_E" with a KO line to the next part of your process....
    Basically you should end up with a loop on new_var2 decementing, and it is used to get a specific next record row from your table.
    Hope this helps, sorry it is a little long winded..
    Edited by: DavidGD on Feb 8, 2009 3:29 PM

  • Reaching the java file outside the package?

    Hi how can i reach the java(or class) files outside the packge(i mean one top folder)
    For example i have a java file in a folder named tech and i want to reach a java file in the folder named support which is under tech folder is something like that possible if it is how?

    Then tech should also be in a package.
    So it would be..
    package tech;
    import tech.support.*;and
    package tech.support;
    import tech.*;

  • Is dll threading treated the same as vi threading?

    I noticed by default my dll built by Visual C++ is set to run in the gui interface subsystem which I assume is equivalent to labview's gui interface thread. Yes?
    I further assume that calling into the dll from any vi running in any thread is equivalent to calling a subroutine vi set to run in the gui interface thread. Yes?
    If yes and yes, and since labview cannot suspend a subroutine vi or the dll, the gui interface thread would be 100% utilized by the call. It would therefore seem, that all other operations occurring in the gui interface thread would be suspended until the call completes, and further more if the dll call is made through a subroutine sub-vi set to run in the caller's thread, then the caller's
    thread would also be suspended. Yes?
    Hence, you could weave yourself into a situation where all other threads are awaiting the execution of gui interface thread. And that then leads to the question of the order in which execution will occur once qued.
    Typically, my threading is separated in my top level vis and the lower level vis are set to run in the caller's thread. But in migrating from LV4.x to LV6i, I never checked my API call dlls execution subsystems, which if the above is correct, may adversely affect my presumed threading...
    So... Assuming the above is true and to avoid it, can I create a dll that runs in the caller's thread, or must the dll's execution thread be specifically set when it is built? More generally, is there a way to avoid this short of insuring that the threads do not compete for the same code resources?
    Thanks,
    Kind Regards,
    Eric
    PS: it might be kinda nice to see the threading identifiable (connections highlighted in various colors
    for example) in the vi hierarchy window...

    My info is marked with ***s.
    > Assuming I specify all dll calls as re-entrant, the number of
    > simultaneous dll calls that can be made from within labVIEW is limited
    > to the number of threads. Specifically, once the dll has control of
    > the thread, nothing else in labVIEW can execute in that thread until
    > the dll call completes. Yes?
    >
    A DLL doesn't normally multitask with other code, but there are
    situations where it does, such as when the DLL decides to process or
    pump messages. The above assumption is pretty accurate, but there are
    things a DLL could do that would void them.
    > If a thread ID were attached to information passed to a labVIEW
    > library function, and that function retained the information for
    > labVIEW, then labVIEW in theory could request the information from the
    > function when the dll call completed. The thread Id would uniguely
    > identify the data because only one dll call can be made with that
    > thread from within labVIEW and of course labVIEW knows which thread is
    > making the call. Yes?
    >
    I'm not sure I understand where this is going. Any DLL is free to pay
    attention to the thread ID, but there is no guarantee that the same
    thread will be used for the VI's next execution, or for the DLL's next
    execution. Information can be stored by the DLL using the threadID, but
    LV doesn't know anything about the information or even which thread
    executed the DLL once it returns.
    Perhaps this info will help out. LV has two ways of executing a DLL
    call. If the DLL call is marked as reentrant, then it will be called in
    the current thread. It is then the DLL's responsibility to protect any
    data or code section that cannot have multiple threads in it simultaneously.
    For compatibility, and to make it easy to protect a DLL call, you can
    mark it as non-reentrant. This will cause the DLL to be swapped over to
    the UI thread so that any other thread trying to call the code at the
    same time will be blocked, and the DLL call will be protected.
    If you have other questions, ask them.
    Greg McKaskle

  • I want to execute [b]some shell [/b]commands in a java program

    Hello,
    I would like to know if it's possible to execute some unix commands in the same "environment"... I mean, if I use the exec() function to execute the "cd /tmp" command, and after that, if I want to do "ls" , I'm not in the "/tmp" directory, know what I mean ??
    In fact, I want to have in my GUI a textarea or something like that, in which one can enter several unix command like in a xterm window...
    I don't know how to do that and if it's possible ??
    Thank you very much for your answers !

    OK !! It works with this code but I don't understand why I have to do "return" twice before the command execute ??
    (I'm a newbie)
    Here's the sample code:
    import java.io.*;
    public class Tonta {
    private String dada="";
    private BufferedReader in;
    private InputStream instr;
    private InputStream errstr;
    private PrintStream outstr;
    private Process transyt;
    private Tonta t;
    public Tonta() {
    //Executem el programa
    try {
    transyt=Runtime.getRuntime().exec("ksh");
    System.out.print("toto");
    } catch (IOException e)
    {System.out.println("EXCEPCION:exec"+ e.getMessage());}
    instr= transyt.getInputStream();
    errstr= transyt.getErrorStream();
    outstr= new PrintStream(transyt.getOutputStream());
    in = new BufferedReader( new InputStreamReader(System.in));
    }//end of constructor
      public void run() {
        int exit=0;
        boolean processEnded= false;
        try {
          while (!processEnded) {
            try {
              exit = transyt.exitValue();
              processEnded = true;
            catch (IllegalThreadStateException e) {}
            System.out.print("\nREMOT:");
            System.out.flush();
            int n= instr.available();
            if (n>0) {
              byte[] pbytes= new byte[n];
              instr.read(pbytes);
              System.out.print(new String(pbytes));
              System.out.flush();
            n= errstr.available();
            if (n>0) {
              byte[] pbytes= new
              byte[n];
              errstr.read(pbytes);
              System.err.print(new
              String(pbytes));
              System.err.flush();
            System.out.println();
            System.out.print("LOCAL> ");
            System.out.flush();
            dada= in.readLine();
            if (dada.equals("exit")) {
              System.out.println();
              System.out.println("Programa finalizado");
              System.out.flush();
              transyt.destroy();
              instr.close();
              errstr.close();
              outstr.close();
              System.exit(0);
            outstr.println(dada);
            outstr.flush();
            try {
              Thread.sleep(10);
            catch (InterruptedException e) {}
          System.out.println();
          System.out.println("Process exited with:"+ exit);
          System.out.flush();
        } catch (IOException e) {
            System.err.println("EXCEPCION "+ e.getMessage());
    public static void main (String [] args) {
    Tonta t= new Tonta();
    t.run();
    }Thanks

  • Through Java code I want to execute a exe file which is in aJar file

    I am having some classes and an exe file in a directory. I have made them in to a Jar file. In a class file which is in that jar file i want to execute a Exe file which is also resides in that jar file. Is it possible to exexute that EXE file?
    For Example....
    1. Im having a directory named CLIENT.
    2. In that directory I have 10 clss files and an EXE file.
    3. These class files and EXE files are ziped in to a Jar file.
    4. I have to give the Jar file to my client.
    5. He can put that Jar file where ever he installed my product may be C driver or D drive like that
    Now the problem is...
    I want to execute the Exe File from one of the class where both the exe file and class file resides in the Jar file
    This is my requirment
    Can anyone Help to me to solve this problem?
    Thanks in Advancd
    Ibram Shah.A.M
    ([email protected])

    The answer is to extract the EXE into a temp directory, execute it, and delete it when you're done. For example:
    //This is the path *inside* the JAR file!
    InputStream in = getClass().getResourceAsStream("/resources/myprog.exe");
    OutputStream out = new FileOutputStream("myprog.exe");
    File file = new File("myprog.exe");
    int data;
    while((data = in.read()) >= 0) out.write(data);
    in.close();
    out.close();
    //Execute the EXE here using java.lang.Runtime.exec()
    if(file.exists()) file.delete();
    ...

  • Methode who execute an other java program

    Hi!
    Is there anyone who know a method who can execute an other java program from an applet?
    Thanks
    Julien

    Depends where the classes of the other program are located. A java program is just a collection of classes, with one particular one regarded as the main one. If you know the main class of the other program at compile time you can just invoke it like any normal method.
    Something like:
    MyOtherProgram.main(new String[]{"first parameter", "second parameter"});(assuming that it's just a standard "command-line" kind of program.)
    If you don't know the class name at until runtime it's still farly straightforward:
    something like
    import java.reflect.*;
    String theOtherProgram = ......
    Class otherP = Class.forName(theOtherProgram);
    String [] params = {"first parameter", "Second parameter"};
    Method theMain = otherP.getMethod("main", new Class[]{params.getClass()));
    theMain.invoke(null, params);

  • Java threading problem... threads only work on 1 processor

    I've got a iterative deepening problem that i have to parallelize. As far as i know i did everything correctly however everything seems to be running on 1 processor instead of 2 processors. As far as i know i am using threads (-Xprof either defines them as thread-1 thread-2 or pool1-thread1,depending on the method used for issueing)
    the worker thread is:
    public int solutionsT(Board board, int currentDepth) {
            int temp = 0;
            int result = 0;
            if (board.distance() == 0) {
               return 1;
            if (board.distance() > board.bound()) {
                return 0;
            Board[] children = board.makeMoves();
            result = 0;
            for (int i = 0; i < children.length; i++) {
                if (children[i] != null) {
                    temp = solutionsT(children, currentDepth + 1);
    if(temp != 0){
    result += temp;
    return result;
    public void run() {
    int temp =0;
    int i = 0;
    while(true){
    while(bag.size() !=0){
    bag.putSolution(solutionsT(bag.get(),1));
    try{   
    barrier.await();
    }catch(Exception e){}
    it get's it's input from a bag that is filled before the iteration begins. (once the bag is filled it trips a barrier) this worker thread is a implementation of Runnable
    This piece of code is used to make the thread object and to issue it
    public SolutionThread(int numberOfThreads) {
       thread = numberOfThreads;
       bag = new bagOfBoards();
       barrier = new CyclicBarrier(thread+1);
       if(thread > 1){
          ExecutorService threadExecutor = Executors.newFixedThreadPool( thread );
          solution = new ThreadTest[thread];
          bag = new bagOfBoards();
          for(int i = 0;i<thread;i++){
             solution[i] = new ThreadTest(bag, lock, barrier, i);
             threadExecutor.execute(solution);
    finally this is the code which is used to acces the bag and get a board.
    synchronized public Board get() {
                if (size > 0) {
                size--;
                Board result = bag[size];
                return result;
            } else {
             return null;
        }since this method is synchronized and it always returns something (either null or a board) and the worker tests for this. there is no race condition here.
    furter more. the main thread is a loop. It fills te bags with an intial state. then it trips the barrier and waits for the workers to do the work. the workers then process the bag until it hits zero and then trip the barrier so that the main thread can do the next iteration (and fill the bag)
    p.s. i know the code is a bit messy, but i want to get the threading to work. As of now i relaly don't understand why the threads are just running on 1 processor instead of 2 processors. not only that. the excecution time is nearly the same as that of a sequential equivalent.
    p.s.2 the code is parallisable. and it is run on a smp system.
    Message was edited by:
    jstrike

    i'm very sure that the jvm and os support smp. the
    problem really should be in the code.I don't see how this can be the case. There's nothing in the Java language that deals with how threads are assigned to processors (at least not as far as I know) so there isn't anything you can do in your code to affect that.
    Or did you meant that i have to tell the jvm in the class that
    there is support for multiple processorsThat would be the only possibility. I have no idea whether it can be done or not, though.

Maybe you are looking for

  • Time Machine won't back up to internal Drive through AFP?

    Hi All! Heres my Problem. I have a Mac Pro system with 4 Hard Drives installed inside the internal Bays.  I wish to use one for Time Machine for the Clients. On the clients i get the error about it not having the correct AFP version. (I know this is

  • What is the best way to image a Mac HD?

    I have a school with about 60 new iMacs. I would like to create one master image and push out to all the other computers using a external network hard drive. I am installing iWork and BootCamp with XP and a few other programs, all with valid licences

  • Tls certificate option is not visible in account information

    I am an internet service provider and we have changed our server settings recently. I'm trying to support a customer who is using Apple's Mail App for his email. We are both Running Mountain lion 10.8.2 and both running mail 6.2 (1499) On the Account

  • Display Connection Problems?

    My Macbook Pro (15", Early 2011) does not seem to recognize my screen. Specifically, the Display Connecter status in System Profiler reads "No Display Connected" for BOTH the AMD Radeon card and the Intel HD Graphics card. Curiously the Color LCD sta

  • How do I reorient a numbers sheet to landscape for printing?

    How do I reorient my numbers spreadsheet to landscape format to print? I tried using the "Inspector." setting the layout to 11 x 8.5, but it still appears as an 8.5 x 11. Thanks