Thread scheduling problem in WLS5.1

We use a Timer Servlet to schedule some back end tasks, however we found
          that from time to time the thread scheduling often get delayed or ahead in a
          outragous magtitude.
          We run the servlet inside WLS, and right after start up, the timer works
          perfect, but after long enough time (more than one day), the timer started
          to behave weird. It could get delayed for as much as hours, and then
          suddenly fired up all delayed tasks in a very short period of time. We then
          try to run a very simple Timer doing only wake up every 10 minutes and print
          one line, that failed too. We are running WLS5.1+sp3 on
          Solaris2.6(Generic_105181-19 sun4u sparc SUNW,Ultra-5_10) with jdk1.2.1_04.
          BTW, we found that it ran well on NT, at least for three days without
          problem.
          Any feedback will be appreciated!
          Qingxiang Ke
          below is the source for the simple timer, and deploy properties for it
          inside weblogic.properties file.
          SimpleTimerServlet.java
          package com.cysive.test;
          import java.io.*;
          import java.util.*;
          import javax.servlet.*;
          import javax.servlet.http.*;
          public class SimpleTimerServlet extends HttpServlet
          class Sleepy implements Runnable
          public void run()
          while(true)
          try
          long wakeUpTime = 600 * 1000;
          Thread.currentThread().sleep(wakeUpTime);
          System.out.println(new Date().toString() + " SimpleTimer Yawn
          ............ Yawn ............");
          catch(InterruptedException ie){}
          private static boolean timerIsRunning = false;
          public void init()
          if(! timerIsRunning)
          Thread sleepy = new Thread(new Sleepy());
          sleepy.start();
          timerIsRunning = true;
          public void doGet(HttpServletRequest request,
          HttpServletResponse response)
          throws IOException, ServletException
          doPost(request, response);
          public void doPost(HttpServletRequest request,
          HttpServletResponse response)
          throws IOException, ServletException
          OutputStream os = response.getOutputStream();
          os.write("look at your std out!!!".getBytes());
          os.flush();
          os.close();
          deploy properties in weblogic.properties
          weblogic.httpd.register.simpletimer=com.cysive.test.SimpleTimerServlet
          weblogic.system.startupClass.servletSimpleTimer=weblogic.servlet.utils.Servl
          etStartup
          weblogic.system.startupArgs.servletSimpleTimer=servlet=simpletimer
          

We use a Timer Servlet to schedule some back end tasks, however we found
          that from time to time the thread scheduling often get delayed or ahead in a
          outragous magtitude.
          We run the servlet inside WLS, and right after start up, the timer works
          perfect, but after long enough time (more than one day), the timer started
          to behave weird. It could get delayed for as much as hours, and then
          suddenly fired up all delayed tasks in a very short period of time. We then
          try to run a very simple Timer doing only wake up every 10 minutes and print
          one line, that failed too. We are running WLS5.1+sp3 on
          Solaris2.6(Generic_105181-19 sun4u sparc SUNW,Ultra-5_10) with jdk1.2.1_04.
          BTW, we found that it ran well on NT, at least for three days without
          problem.
          Any feedback will be appreciated!
          Qingxiang Ke
          below is the source for the simple timer, and deploy properties for it
          inside weblogic.properties file.
          SimpleTimerServlet.java
          package com.cysive.test;
          import java.io.*;
          import java.util.*;
          import javax.servlet.*;
          import javax.servlet.http.*;
          public class SimpleTimerServlet extends HttpServlet
          class Sleepy implements Runnable
          public void run()
          while(true)
          try
          long wakeUpTime = 600 * 1000;
          Thread.currentThread().sleep(wakeUpTime);
          System.out.println(new Date().toString() + " SimpleTimer Yawn
          ............ Yawn ............");
          catch(InterruptedException ie){}
          private static boolean timerIsRunning = false;
          public void init()
          if(! timerIsRunning)
          Thread sleepy = new Thread(new Sleepy());
          sleepy.start();
          timerIsRunning = true;
          public void doGet(HttpServletRequest request,
          HttpServletResponse response)
          throws IOException, ServletException
          doPost(request, response);
          public void doPost(HttpServletRequest request,
          HttpServletResponse response)
          throws IOException, ServletException
          OutputStream os = response.getOutputStream();
          os.write("look at your std out!!!".getBytes());
          os.flush();
          os.close();
          deploy properties in weblogic.properties
          weblogic.httpd.register.simpletimer=com.cysive.test.SimpleTimerServlet
          weblogic.system.startupClass.servletSimpleTimer=weblogic.servlet.utils.Servl
          etStartup
          weblogic.system.startupArgs.servletSimpleTimer=servlet=simpletimer
          

Similar Messages

  • Thread scheduling mechanism in SUN's VM

    I've the problem, that n threads share a resource
    (sharedObject).
    The synchronization is done in an synchronized
    Block:
    synchronized( sharedObject )
    // do something with sharedIbject
    I would like to know in which order the thread scheduler
    of SUN Solaris VM of the JDK 1.3 or in general,
    gives the lock of the sharedObject to one of the thread, which
    are waiting for the lock of the sharedObject.
    Is there something like FIFO, so that it's safe, that all waiting
    threads will get the sharedObject in the right order,
    or do i have to implement a queueing mechanism with wait and
    notify.
    thanks

    If you're writing a Java program that uses threads, the thing to do is to follow the rules that Java provides, not the rules of a particular thread scheduler.
    There is no guarantee about which order the threads will get access to the sharedObject without writing explicit code for it.

  • Thread Scheduling Query

    Hi,
    If i have 3 messages A, B and C which are in a queue and are to pass through a synchronized method Y . A particular thread X picks 1 message each from the queue and spawns a thread for each of 3.
    A is executing Y and B and C are in BLOCKING State and waiting for A to finish so that they can enter Y.
    Is it possible that C executes first before B.
    Pls advice.
    Thnx in Adv
    Amandeep

    Setting a thread's priority is not the preferred solution namely because it is dangerously inconsistent. The only time to use thread priority is when you have tasks that do not have scheduling conflicts like this and you really don't care when a particular thread runs. As an example the garbage collection thread in a VM is normally a lower priority thread until such time that garbage collection is needed.
    The preferred solution for thread scheduling and order of executing issues is to revisit the design.
    In the example given by the OP I would first question the use of multiple threads at all. It seems that the OP wished tasks to be executed from a queue in the same order as they were added to the queue and that tasks later in the queue should not finish execution before ones earlier.
    This does not seem a good use for multiple threads because this requirement seems to call for anything but parallel execution.
    But perhaps I am reading too much into that statement. I would suggest a revist of the design though to look at doing the following.
    Launcher thread
    1) Gets next thing from queue
    2) Calls synchonized Y method (that no longer needs to be synchronized probably) using thing from queue
    3) Starts new thread with results from Y
    4) Go back to 1
    This design garauantees at least that the launcher threads will be started (and past the synchronized method) in the same order as they were received.
    Does that mean they will complete execution in the same order? No. Does it mean they will actually start processing in the same order? No. But it does mean they will call Y in the same order and since I would guess that is the real issue here it solves the problem.
    If the threads really must finish in the same order than one must consider either; not running seperate threads as I mentioned earlier or adding a semaphore at the end of the spawned "worker" threads so that they wait for previous threads to finish before exiting.

  • IS a thread scheduler part of JVM or OS ?

    Hi Folks,
    Just curious if the thread scheduler is a part of the JVM or OS, or either or both ?
    I tried few thread pages in JLS,but couldnot locate the exact sentence describing this.
    However some other resources have given me contradicting information.
    For example, [Reference1|http://www.deitel.com/articles/java_tutorials/20051126/JavaMultithreading_Tutorial_Part3.html] states that it is a part of the OS,whereas [Reference2|http://book.javanb.com/java-threads-3rd/jthreads3-CHP-9-SECT-1.html] states that it is a part of both.(I am not sure about the authority of these links.)
    So assuming, thread scheduling is done by JVM it is a part of the JVM only or it uses the underlying OS for support.
    Thank you for the consideration.

    This statement:
    The JVM ... operates like a mini OS and schedules its own threads regardless the underlying operating system.flatly contradicts this statement:
    In some JVMs, the java threads are actually mapped to native OS threads.They cannot both be true.
    Therefore we can say that Threads are part of JVM and OS bothRubbish. There's no 'therefore' about it. You can't draw valid logical inferences from contradictions.
    Guesswork and invalid inferences aside, the fact of the matter is that the semantics of Java threads are specified in the JLS but the execution mechanism is not. 'Any execution strategy that generates only allowed behaviors is an acceptable execution strategy.'
    I am not sure about the authority of these linksNil. They are extracts from books by third parties. Use at own risk. The JLS is where the authority is.
    Reference 2 is particularly poor, as it contradicts itself numerous times.
    For the record, Reference 2 also makes the following claims which as far as I can see are entirely baseless, for the reasons given:
    A Java virtual machine is required to implement a preemptive, priority-based schedulerThe word 'pre-emptive' does not appear in the JLS.
    The Java virtual machine never changes the priority of a thread, even if the thread has been running for a certain period of timeCan't find that anywhere either.
    the contract between the Java virtual machine and the underlying operating system is that the operating system must generally choose to run the Java thread with the highest priorityThe 'contract' is between the Java code and the JVM, not the JVM and the O/S.
    That's what we mean when we say that Java implements a priority-based schedulerJava isn't required to 'implement' a scheduler at all.
    This scheduler is implemented in a preemptive fashion, meaning that when a higher-priority thread comes along, that thread interrupts (preempts) whatever lower-priority thread is running at the time.This appears nowhere in the JLS.
    The contract with the operating system, however, is not absolute, which means that the operating system can sometimes choose to run a lower-priority thread.In other words it's not pre-emptive. Make up your mind.
    Java's requirement for a priority-based, preemptive scheduling mechanism ...Which is nowhere to be found.
    A Java thread can have one of 11 prioritiesMIN_PRIORITY is 1, MAX_PRIORITY is 10: that makes 10, not 11.
    In fact, preemption means only that a higher-priority thread runs instead of a lower-priority oneNo it doesn't. It means that when a higher-priority thread becomes ready it pre-empts the execution of any lower-priority threads that are currently executing regardless of time-slice etc. This is a feature of real-time systems that Java is not required to implement.
    Summing up, the words 'pre-emptive' does not appear in the JLS, and the word 'scheduler' only appears in reference to sleep() and yield(), without any implication that the JVM has to implement one itself.

  • Production Orders: Scheduling Problem

    Hello
    I have a scheduling problem.  I want the system to calculate the production order dates.
    I have maintained the following
    1.      Work Center:  A formula to calculate the duration.  I have marked the u201Crelevant to finite indicatoru201D in the Capacity Header Tab.  I have also maintained the available capacity as 24 Hrs.
    2.     Routing:  I have maintained the values for the standard value keys
    3.     SPRO:  In scheduling parameters for the order type, I have marked u201CGenerate cap requirementsu201D and u201CSchedulingu201D;  In the production scheduling profile, I have marked u201CSchedule orderu201D (on release) & u201CFinite Schedulingu201D (Availability check).
    But the production order is not getting scheduled & the start & end times are the same.  I get the error u201CNo req/capacity exists or not relevant for finite schedulingu201D.
    Can anyone guide me as to what I am missing?
    Best regards
    Tom

    Dear Tom,
    Please check following;
    1. Your operation contol key; whether it allows scheduling.
    2. scheduling parameters for production order on OPU3: Please select proper combination of plant and order type and tick scheduling and generate capacity requts indicators in detailed scheduling tab.
    Please revert back if problem persist.
    Best Regards
    Uday

  • Thread scheduling

    Hi, I have some questions bout threads.
    1) When it comes to thread scheduling, Java has no say in it, since thread scheduling is solely in a domain of operating system?
    2)In preemptive environment, when thread with higher priority becomes runnable, runtime will cause lower priority thread to halt and higher priority thread to start executing. This chosen thread will run until one of the following conditions is true:
    - a higher priority thread becomes "Runnable"
    - it yields, or its run() method exits
    - on systems that support time-slicing, its time has expired
    a) Time slicing doesn't mean that every thread will get the same amount of time to run?
    b)Will higher priority threads get more time and lower less!
    c) Does Windows OS support time slicing?
    3)What kind of environment is non-preemptive environment? The kind where threads with higher priority cant preempt lower priority threads? As I understand it, in those kind of environments there is a greater chance that some threads will never run. Why?
    4)Why is under non-preemptive environment greater chance of having situation where one of the two threads with same priority will not get a chance to run?
    bye

    beginprog wrote:
    1) When it comes to thread scheduling, Java has no say in it, since thread scheduling is solely in a domain of operating system?This is not strictly true. You can control when a thread is eligible to run, but you can't force a partiular thread to run. The JVM has some control over thread scheduling, but yes, it also interacts with the OS.
    2)In preemptive environment, when thread with higher priority becomes runnable, runtime will cause lower priority thread to halt and higher priority thread to start executing. This chosen thread will run until one of the following conditions is true:
    - a higher priority thread becomes "Runnable"
    - it yields, or its run() method exits
    - on systems that support time-slicing, its time has expired I don't think Java makes any such promises about its threads' priorities. You may be describing a general model, but in terms of the JVM scheduling its threads, higher priority threads will be preferred over lower priority ones, but the exact algorithm is left up to the implementation.
    a) Time slicing doesn't mean that every thread will get the same amount of time to run? There are many ways to implement time slicing. It depends on the VM implementation and the OS.
    b)Will higher priority threads get more time and lower less!Depends on the implementation.

  • Sol 9 thread scheduling

    I posted this yesterday in the kernel forum because thread scheduling seemed more like a kernel issue than the generally admin type things usually discussed here, but I've not had any takers in kernel, so I'm trying here. Basically, while porting an application from solaris 8 to solaris 9, I seem to have run into a starvation issue with the new 1x1 thread model.
    Here is a link to the post in the kernel forum:
    http://forum.sun.com/thread.jsp?forum=10&thread=18592&tstart=0&trange=100
    Any help would be appreciated.

    I wonder why results were same. I replaced sleep(10) with an arbitrary number of busy loops, 100000
    I do see that all threads get a chance to run. I am running a 2 CPU ultrasparc each running at 1002 MHz. I do not have an understanding of your application though, but as others mentioned feel that mutexes should be used to protect critical sections (which would be small) or as a mechanism to wakeup in an async manner along with condition variables.
    pthread_starvation: press ^C to interrupt.
    Thread 6 waited 0 milliseconds.
    Thread 11 waited 5 milliseconds.
    Thread 10 waited 5 milliseconds.
    Thread 9 waited 6 milliseconds.
    Thread 8 waited 6 milliseconds.
    Thread 7 waited 7 milliseconds.
    Thread 2 waited 7 milliseconds.
    Thread 3 waited 7 milliseconds.
    Thread 4 waited 8 milliseconds.
    Thread 5 waited 8 milliseconds.
    Thread 6 waited 0 milliseconds.
    Thread 11 waited 0 milliseconds.
    Thread 10 waited 0 milliseconds.
    Thread 9 waited 0 milliseconds.
    Thread 8 waited 0 milliseconds.
    Thread 7 waited 0 milliseconds.
    Thread 2 waited 0 milliseconds.
    Thread 3 waited 0 milliseconds.
    -madhusudan

  • Scheduling problem in LSMW for Sales Order

    I am doing LSMW for Sales Order using the BAPI method.
    I am able to upload the item details along with their quantities also but the problem that I am now facing is the scheduling problem.I am unable to schedule the item quantities, only the last quantity passed is taken as the final quantity and the consolidated quantity is also getting ignored.
    I am using E1BPSCHDL structure, in this structure I am mapping Itm_number , req_date and req_qty(scheduled qty).....
    in the structure E1BPSCHDLX, the same fields are mapped as 'X'.
    in the structure E1BPSDITM, I am mapping the item info along with the consolidated qty(TARGET_QTY), but this is getting ignored and the last scheduled qty is taken as the final consolidated qty and the rest scheduled qty data is getting rejected.
    Please do help... I dont know why this problem is coming... tried n number of alternatives but of no hope... do try to help me
    with regards,
    Daya.

    Check the format of your date and check the format expected.
    sometimes you can have diff like YYYYMMDD, MM.DD.YYYY,...
    Look at the converted data.
    Hope this helps,
    Erwan

  • Thread Scheduling Visualizer - take a look

    Hi,
    I want to share this link with all the sun forum members.
    It is about "The Sun Java Real-Time System Thread Scheduling Visualizer"
    [http://java.sun.com/javase/technologies/realtime/reference/TSV/JavaRTS-TSV.html]
    Sun you are simply too great ;)
    thanks,
    swapnaja
    Edited by: swapnaja on Mar 16, 2009 6:43 AM
    Edited by: swapnaja on Mar 16, 2009 6:48 AM

    Hi,
    Glad it worked for you too. I'm so grateful to 'turboontheovens' for posting this solution, it was driving me crazy!
    Claire x

  • Question about synchronize() statement and thread scheduling?

    I have threads accessing a shared LinkedList in the main thread. I made use of the Collections.synchronizedList() to avoid concurrent modifications. one of the threads is a timer thread and it has a priority of 5 and the other threads are message reception threads and i made them of a lower priority just to allow the timer thread to be executed on time. According to the javaAPI, all iterations on the synchronized list should be done using synchronized(synchronizedListRef){} and this is what i do,
    The problem is even after setting the priority of the reception threads lower than the timer thread, the reception threads are sometimes executed more than once and the timer thread is delayed. Lets assume the situation where the timer reaches the point where it has to acquire the lock (the synchronized statement) and it discovers that the lock is already taken and it cant access the list because the other thread (of a lower priority) is iterating over it. shouldnt the higherpriority thread be executed after that the reception thread (that is blocking the timer thread) finishes its execution and release the lock (even if there are other reception thread waiting)??
    does the priority play a role when a thread is blocked?

    Asady wrote:
    I have threads accessing a shared LinkedList in the main thread. I made use of the Collections.synchronizedList() to avoid concurrent modifications. Make sure you explicitly sync around all iterations. Just using Collections.sync is not enough.
    The problem is even after setting the priority of the reception threads lower than the timer thread, the reception threads are sometimes executed more than once and the timer thread is delayed.There's no guarantee as to how priority will be interpreted. The scheduler implementation is free to do pretty much anything.
    As for how to solve your problem, you might want to look at java.util.concurrent.*, e.g. PriorityQueue. If the classes there don't give you just what you need, you may be able to build on them, or at least get ideas from them. Bottom line is that if you want a specific scheduling algorithm, you'll have to implement it yourself, since Threads' priority semantics are only very loosely specified by the JLS.

  • Thread Problem - (Thread Blocking Problems?)

    Hi Friends
    In my program while using thread i found a problem in this code .
    In this whlie running the 'msg' was printen only after all 5 inputs are given .
    why i was not getting output after one input.why the thread out was waiting for remaining threads input.
    my code is
    import java.io.*;
    class MyThread extends Thread
      BufferedReader bin;
       MyThread()
         super();
         start();
       public void run()
          try
           bin=new BufferedReader(new InputStreamReader(System.in));
           String msg=bin.readLine();
           System.out.println(msg);
          catch(IOException e)
             System.out.println(e);
    public class Threads
         public static void main(String args[])
              for(int i=0;i<5;i++)
                new MyThread();
    }

    Hi Friends
    In my program while using thread i found a problem
    em in this code .
    In this whlie running the 'msg' was printen only
    after all 5 inputs are given .
    why i was not getting output after one input.why
    hy the thread out was waiting for remaining threads
    input.Probably because of how the scheduler was rotating among the threads while waiting for input and queueing up output.
    When you call readLine, that thread blocks until a line is available. So it probably goes to the next thread's readLine, and so on. All threads are probably blocked waiting for input before you enter a single character.
    Something inside the VM has to coordinate the interaction with the console, and between that and your threads, the out stuff just doesn't get a chance to display right away.
    In general, you can't predict the order of execution of separate threads.

  • OBI 10g iBot scheduling problem to deliver report

    Hi ,
    I have done with iBot configuration(OBI 10g ) as mentioned in the oracle documentation .
    But when I try to schedule one report immediately I am getting the below error from : C:\OracleBIData\web\log\sawlog0.log file :
    One thing I am bit surprised in below error : RemoteIP-1x.xxx.xx.x is picking my local IP . Is it okay or it should be the SMTP mail server IP ?
    Could anyone help how to fix the below problem :
    Type: Error
    Severity: 42
    Time: Thu May 08 20:04:09 2008
    File: project/websubsystems/ssremote.cpp Line: 1515
    Properties: ThreadID-928;HttpCommand-IBotPicker;RemoteIP-1x.xxx.xx.x;User-Administrator
    Location:
         saw.httpserver.request
         saw.rpc.server.responder
         saw.rpc.server
         saw.rpc.server.handleConnection
         saw.rpc.server.dispatch
         saw.threadPool
         saw.threads
    ***kmsgNoDisconnectedApplicationFound: message text not found ***
    Type: Error
    Severity: 42
    Time: Thu May 08 20:04:21 2008
    File: project/websubsystems/ssremote.cpp Line: 1515
    Properties: ThreadID-928;HttpCommand-IBotPicker;RemoteIP-1x.xxx.xxx.x;User-Administrator
    Location:
         saw.httpserver.request
         saw.rpc.server.responder
         saw.rpc.server
         saw.rpc.server.handleConnection
         saw.rpc.server.dispatch
         saw.threadPool
         saw.threads
    ***kmsgNoDisconnectedApplicationFound: message text not found ***

    Hi,
    Any chance you were able resolve this issue, Please share the resolution steps.
    thanks in advance.

  • SBO Backup schedule problem

    Hi,
    When i try to schedule de SBO Backup in the SAP Service Manager to "daily" and click oke, then it always switches back to "on specific date"
    What is my problem?
    Greetings
    Mark

    Hi Mark,
    Thanks for the details, we were checking all the fixes included in version 2007A in regard the backup services and not similiar issue had been reported.
    The change in the backup frequency could be related to a third party application as Anti-virus a/o spyware reseting the system values to the previous one.
    As already commented in this thread, it will be advisable to reinstall the server tools or make the proper changes to allow you antivirus to take the change.
    If still facing the issue after applying previous recommendations, please generate and forward a message to Business One support including all the details from your test and observations.
    Regards,
    Juan Manuel Marrero
    SAP Business One Forums  Team

  • Java Threads compilation problem

    Hi everyone,
    I've having problems getting a simple thread program to compile, the programs says " ; " expected when there is already one present. I've gone through the program many times and still can't put my finger on whats going wrong. If someone could take a quick look and if possible tell me where I am going wrong.
    Many Thanks
    Its class ThreadA that will not compile
    ***code********************************************
    public class ThreadA extends Thread
    private int id;
    public ThreadA(int i) (id = i);
    public void run()
    for (int i=0}; i < 10; i++);
    try {sleep(1000};)catch (InterruptedException e)();
    System.out.println("Output from Thread " + id);
    import java.io.*;
    public class TestThreads1
    public static void main (String args [] )
    Thread t1 = new ThreadA (1);
    Thread t2 = new ThreadA (2);
    Thread t3 = new ThreadA (3);
    t1.start();
    t2.start();
    t3.start();
    **code***********************************************************

    public class ThreadA extends Thread
    private int id;
    public ThreadA(int i) (id = i); // <-- problem
    public void run()
    for (int i=0}; i < 10; i++); // <-- two problems
    try {sleep(1000};)catch (InterruptedException e)(); // <-- more problems
    System.out.println("Output from Thread " + id);
    }

  • 64-bit JNI C++ to JAVA invocation multiple threads classloader problem

    Hi ALL,
    I have a C++ app that invokes Java classes on 64-bit Solaris 10 with 64-bit JVM.
    Here is the problem:
    The native non-main (not the thread that initializes the JVM) threads would not be able to find any user-define class.
    Here are the symptoms and observations:
    1. JNIEnv::ExceptionDescribe() showed the following StackOverflowError:
    Exception in thread "Thread-0" java.lang.StackOverflowError
            at java.util.Arrays.copyOf(Arrays.java:2734)
            at java.util.Vector.ensureCapacityHelper(Vector.java:226)
            at java.util.Vector.addElement(Vector.java:573)
            at java.lang.ClassLoader.addClass(ClassLoader.java:173)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)2. The "main thread" that instantiates the JVM has no problem finding and loading any class or method
    3. But the other threads (non-main threads) would not be able to find the user-defined classes unless the classes were already loaded by the main thread.
    4. The non-main threads can find the "standard" java classes with no problem
    5. The same app ran fine on 32-bit system.
    6. Except for the JVM reference is global, each thread acquired JNIEnv by either GetEnv() or AttachCurrentThread().
    Any idea why it is a problem with 64-bit?
    I have the sample program to reproduce this issue in this thread: http://forums.sun.com/thread.jspa?messageID=10885363&#10885363. That was the original thread I raised but I have narrowed it down to a more concrete scenario. That's why I am creating this new thread. I hope this does not break any rule on this forum. If it does, I apologize.
    I really appreciate it if anyone can provide any help/suggestion.
    Regards,
    - Triet

    Here is the sample program. Again, this works on 32-bit but not 64-bit.
    #include <string>
    #include "jni.h"
    #include "TestThread.h"
    static JavaVM *g_pjvm = NULL;  /* denotes a Java VM */
    static JNIEnv *g_penv = NULL;  /* pointer to native method interface */
    void initJVM(char** jvmOptions) {
        printf("RJniTest init starts...\n");
        JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
        JavaVMOption* poptions;
        int optionLen = 0;
        while (jvmOptions[optionLen]) {
            optionLen++;
        printf("RJniTest::init len=%d\n", optionLen);
        if (optionLen > 0) {
            printf("RJniWrapper::init jvmOptions\n");
            poptions = new JavaVMOption[optionLen];
            //poptions[0].optionString = "-Djava.class.path=/usr/lib/java";
            int idx = 0;
            while (jvmOptions[idx]) {
                poptions[idx].optionString = jvmOptions[idx];
                idx++;
        printf("RJniTest::init vm_args: version(%x), nOptions(%d)\n",
                JNI_VERSION_1_6, optionLen);
        vm_args.version = JNI_VERSION_1_6;
        vm_args.nOptions = optionLen;
        vm_args.options = poptions;
        vm_args.ignoreUnrecognized = JNI_FALSE;
        // load and initialize a Java VM, return a JNI interface
        // pointer in env
        printf("RJniTest::init creates JVM\n");
        JNI_CreateJavaVM(&g_pjvm, (void**)&g_penv, &vm_args);
        printf("RJniTest init ends\n");
    void findClass(const char* classname) {
        static const char* fname = "justFindClasses";
        printf("%s: findClass: %s\n", fname, classname);
        JNIEnv* jenv;
        jint ret = g_pjvm->GetEnv((void**)&jenv, JNI_VERSION_1_6);
        if (ret == JNI_EDETACHED) {
            ret = g_pjvm->AttachCurrentThread((void**)&jenv, NULL);
            if (ret != JNI_OK || jenv == NULL) {
                printf("%s: get env error: ret=%d\n", ret, fname);
            } else {
                printf("%s: got new env\n", fname);
        } else if (ret == JNI_OK) {
            printf("%s: env already there\n");
        jclass classref;
        classref = jenv->FindClass(classname);
        if (classref == NULL) {
            printf("%s: %s class not found!\n", fname, classname);
            if (jenv->ExceptionOccurred()) {
                jenv->ExceptionDescribe();
                jenv->ExceptionClear();
        printf("%s: found class: %s\n", fname, classname);
    class RJniTestThread : public TestThread {
    public:
        void threadmain();
    void RJniTestThread::threadmain() {
        printf("RJniTestThread::threadmain: Starting testing\n");
        findClass("org/apache/commons/logging/Log");
        findClass("java/util/List");
        printf("RJniTestThread::threadmain: done.\n");
    int main(int argc, char** argv) {
        char **jvmOptions = NULL;
        printf("RJniTestDriver starts...\n");
        if (argc > 1) {
            jvmOptions = new char*[argc];
            for (int i = 0; i < argc ; i ++) {
                jvmOptions[i] = argv[i + 1];
            jvmOptions[argc - 1] = NULL;
        } else {
            int size = 8;
            int i = 0;
            jvmOptions = new char*[size];
            jvmOptions[i++] = (char*) "-Djava.class.path=<list of jar files and path here>";
            jvmOptions[i++] = (char*) "-Djava.library.path=/sandbox/mxdev/3rdparty/java/unix/jdk1.6.0_14/jre/lib/sparc";
            jvmOptions[i++] = (char*) "-Djava.compiler=NONE";
            jvmOptions[i++] = (char*) "-verbose:jni";
            jvmOptions[i++] = (char*) "-Xcheck:jni";
            jvmOptions[i++] = NULL;
        printf("init JVM\n");
        initJVM(jvmOptions);
        // UNCOMMENT HERE
        // findClass("org/apache/commons/logging/Log");
        // findClass("java/util/List");
        // UNCOMMENT END
        printf("start test thread\n");
        RJniTestThread testThread;
        ThreadId tid = testThread.launch();
        printf("wait for test thread\n");
        int ret = pthread_join(tid, NULL);
        printf("RJniTestDriver ends\n");
    }

Maybe you are looking for