Object.wait(): IllegalMonitorStateException: current thread not owner

How can I identify the owner? I searched the Thread*-Classes but didn't see any method which identifies the owner.

Or, from the documentation for Object.wait():
     * The current thread must own this object's monitor.and
     * This method should only be called by a thread that is the owner
     * of this object's monitor. See the <code>notify</code> method for a
     * description of the ways in which a thread can become the owner of
     * a monitor. and
     * @exception  IllegalMonitorStateException  if the current thread is not
     *               the owner of the object's monitor.Seems like a lot of people are getting broken downloads nowadays that don't include the documentation :-(

Similar Messages

  • Java.lang.IllegalMonitorStateException: current thread not owner

    Hello,
    my program runs an exe that doesn't return a zero when it's finished, therefore, I can't use a waitFor().
    To solve this problem i look at the length of the file which has to be manipulated by this exe every 200ms and see whether it's length stopped changing. This should mean it's job is done...
    But using this code:
    public void run(String filename)
              System.out.println("start runtime");
              Runtime rt = Runtime.getRuntime();
              String[] callAndArgs = { "lssvmFILE.exe", filename };
              try
                   Process child = rt.exec(callAndArgs);
                   child.wait(200);
                   filesize = 0;
                   while(filesize != file.length())                            {
                        filesize = file.length();
                        child.wait(200);
                   //child.waitFor();
                   System.out.println("Process exit code is:   " + child.exitValue());
              catch(IOException e)
              {     System.err.println( "IOException starting process!");}
              catch(InterruptedException e)
              {     System.err.println( "Interrupted waiting for process!");}
              System.out.println("end run");
         }i get this on my System.out:
    Exception occurred during event dispatching:
    java.lang.IllegalMonitorStateException: current thread not owner
            at java.lang.Object.wait(Native Method)
            at LssvmFile.run(LssvmFile.java:292)
            at LssvmFile.start(LssvmFile.java:189)
            at GUI.actionPerformed(GUI.java:137)
            at java.awt.Button.processActionEvent(Button.java:329)
            at java.awt.Button.processEvent(Button.java:302)
            at java.awt.Component.dispatchEventImpl(Component.java:2593)
            at java.awt.Component.dispatchEvent(Component.java:2497)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)

    Here's the code:
    I already found out that the sleep function indeed caused this exe to run so slow. It seems that everything stops when sleep is used. By setting the delay to 2ms the duration is satisfactory (some seconds).
    I also tried skipping the sleep and just using a while, but that ended in an endless loop. Setting the delay to 1ms lead to a stop when the filelength was 0 (i guess that was on the moment that the exe cleared the file and prepared to write) so it seems to me that 2ms is quite a good trade off.
    this part of the code is preceeded by writing the data to the file and afterwards the new data will be read in again...
         //Close the stream
              outFileStream.close();
         //Run lssvmFILE.exe to compute alpha & b
              long originalfilesize = file.length();
              run(filename);
              //wait untill job done
              Thread thread = new Thread();
              long filesize = file.length();
              try{thread.sleep(2);}
              catch(InterruptedException e){};
              while(filesize != file.length() || originalfilesize ==file.length())
                   filesize = file.length();
                   try{thread.sleep(2);}
                   catch(InterruptedException e){};
         //Set up Instream (read from file)
         //----------------------Bedankt!
    Bart

  • IllegalMonitorStateException: current thread not owner

    Hello I'm a new french developper in JAVA.
    I have problems to launch a command from my main class.
    Here is the method :
    private static boolean ConvertToPDF(Vector HTMLPath, String PDFPath, boolean DeleteHTMLSourceFile) {
              boolean      ConvertOK           = false;
              String           HTMLDocCommand      = "";
              String           HTMLSourcePath     = "";
              String           command;                // Command string
              Process      process;                // Process for HTMLDOC
              Runtime      runtime;                // Local runtime object
              InputStream input;
              byte           buffer[];
              int           bytes;
              // R�cup�ration du chemin du r�pertoire tampon HTML dans le fichier general.properties
             try {
                  mailProperties = (PropertyResourceBundle) ResourceBundle.getBundle("General");
             catch (MissingResourceException e) {
                  System.out.println("ConvertToPDF - Impossible de localiser le fichier general.properties");
             HTMLDocCommand = mailProperties.getString("HTMLDocCommand");
             for (int i=0;i<HTMLPath.size();i++){
                  HTMLSourcePath += (String) HTMLPath.elementAt(i) + " ";
              command = HTMLDocCommand+" "+PDFPath+" "+HTMLSourcePath;
              // Lancement du processus et attente de fin ...
              runtime = Runtime.getRuntime();
              try
                   process = runtime.exec(command);
                   System.out.println("D�but attente du processus");
                   process.notifyAll();
                   bytes = process.waitFor();
                   process.notifyAll();
                   System.out.println("Fin attente du processus");
                   // V�rification de l'existence du fichier de sortie
                   File PDFFile = new File(PDFPath);
                   if (PDFFile.exists())
                        ConvertOK = true;
                   else
                        ConvertOK = false;
              catch (Exception e)
                   ConvertOK = false;
                   System.out.print(e.toString() + " caught while running:\n\n");
                   System.out.print(" " + command + "\n");
              return ConvertOK;
         }When I Executing my class (from a windows command prompt) i Have this error message :
    IllegalMonitorStateException: current thread not owner caught while running <mycommand>
    I have also tried to use the "synchronied method" :
    private static boolean ConvertToPDF(Vector HTMLPath, String PDFPath, boolean DeleteHTMLSourceFile) {
              boolean      ConvertOK           = false;
              String           HTMLDocCommand      = "";
              String           HTMLSourcePath     = "";
              String           command;                // Command string
              Process      process;                // Process for HTMLDOC
              Runtime      runtime;                // Local runtime object
              InputStream input;
              byte           buffer[];
              int           bytes;
              // R�cup�ration du chemin du r�pertoire tampon HTML dans le fichier general.properties
             try {
                  mailProperties = (PropertyResourceBundle) ResourceBundle.getBundle("General");
             catch (MissingResourceException e) {
                  System.out.println("ConvertToPDF - Impossible de localiser le fichier general.properties");
             HTMLDocCommand = mailProperties.getString("HTMLDocCommand");
             for (int i=0;i<HTMLPath.size();i++){
                  HTMLSourcePath += (String) HTMLPath.elementAt(i) + " ";
              command = HTMLDocCommand+" "+PDFPath+" "+HTMLSourcePath;
              // Lancement du processus et attente de fin ...
              runtime = Runtime.getRuntime();
              try
                   process = runtime.exec(command);
    synchronized(process){
                   System.out.println("D�but attente du processus");
                   process.notifyAll();
                   bytes = process.waitFor();
                   process.notifyAll();
                   System.out.println("Fin attente du processus");
                   // V�rification de l'existence du fichier de sortie
                   File PDFFile = new File(PDFPath);
                   if (PDFFile.exists())
                        ConvertOK = true;
                   else
                        ConvertOK = false;
              catch (Exception e)
                   ConvertOK = false;
                   System.out.print(e.toString() + " caught while running:\n\n");
                   System.out.print(" " + command + "\n");
              return ConvertOK;
         }But I have the same error message. Maybe the synchronised is not on the right object ?
    Could anyone help me ?
    Thanks for all.

    - The exception is thrown during process.notifyAll() calls; can u try commenting out those calls?
    - For questions on java, you may also want to try the forum at:
    http://forum.java.sun.com/category.jspa?categoryID=32

  • Current thread not owner

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException: current thread not owner
         at java.lang.Object.wait(Native Method)
         at java.lang.Object.wait(Unknown Source)
         at OneTab.OneForm.OneForm.stop_watch(OneForm.java:104)
         at DraMain_Sub.actionPerformed(DraMain.java:129)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)I just want to know this message.
    "java.lang.IllegalMonitorStateException: current thread not owner".
    What is it?
    try{
    this.wait();
    }catch(InterruptedException e){}I just want to do it.

    my initial guess would be that the OP needs a refresher on wait and
    notify. There are plenty of tutorials available and spending 15 20
    min on one of them would not be a waste of time, trust me!!!!!But this reply did not come from Jos, so it will apparantly be ignored.Hm, if that were true I wouldn't like it one bit. Lots of people give valuable
    advice here and the last thing I would want is a 'status aparte'.
    kind regards,
    Jos

  • Javaws 1.4.2 "current thread not owner"

    Hello everyone,
    I have an application that I have been launching with javaws since the javaws 1.0.x days that won't work with javaws 1.4.2. Does anyone have any clue as to what could be wrong?
    Java Web Start 1.4.2 Console, started Thu Aug 21 09:15:25 EDT 2003
    Java 2 Runtime Environment: Version 1.2.2 by Sun Microsystems Inc.
    --------- EXCEPTION ---------
    java.lang.IllegalMonitorStateException: current thread not owner
         at com.sun.javaws.security.JNLPClassPath.findNamedResourceInLoaders(Unknown Source)
         at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java, Compiled Code)
         at com.sun.javaws.security.JNLPClassPath.findNamedResource(Unknown Source)
         at com.sun.javaws.security.JNLPClassPath.getResource(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
         at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java, Compiled Code)
         at org.apache.xerces.framework.XMLParser.<init>(XMLParser.java)
         at org.apache.xerces.framework.XMLParser.<init>(XMLParser.java)
         at org.apache.xerces.parsers.DOMParser.<init>(DOMParser.java)
         at com.fpl.ima.deployit.options.DeployItOptions.loadOptions(DeployItOptions.java, Compiled Code)
         at com.fpl.ima.deployit.options.DeployItOptions.getInstance(DeployItOptions.java)
         at com.fpl.ima.deployit.DeployIt.initialize(DeployIt.java)
         at com.fpl.ima.deployit.DeployIt.<init>(DeployIt.java)
         at com.fpl.ima.deployit.DeployIt.main(DeployIt.java)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.sun.javaws.Launcher.executeApplication(Unknown Source)
         at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
         at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
         at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
         at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
         at com.sun.javaws.Launcher.run(Unknown Source)
         at java.lang.Thread.run(Thread.java:479)
    Exception occurred in main() of DeployIt
    java.lang.IllegalMonitorStateException: current thread not owner
         at com.sun.javaws.security.JNLPClassPath.findNamedResourceInLoaders(Unknown Source)
         at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java, Compiled Code)
         at com.sun.javaws.security.JNLPClassPath.findNamedResource(Unknown Source)
         at com.sun.javaws.security.JNLPClassPath.getResource(Unknown Source)
         at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
         at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java, Compiled Code)
         at com.fpl.ima.deployit.DeployIt.main(DeployIt.java)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.sun.javaws.Launcher.executeApplication(Unknown Source)
         at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
         at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
         at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
         at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
         at com.sun.javaws.Launcher.run(Unknown Source)
         at java.lang.Thread.run(Thread.java:479)

    I can only guess at the likely cause. Previously (jws 1.2 and earlier) every web start process would kick off a jvm for the web start client to process the jnlp, this would in turn then kick off a second jvm to run the actual application.
    1.4.2 has changed this slightly to improve startup time etc.. the second jvm process doesn't happen, and now the web start app runs from the same jvm that the web start client has started for itself. This is why the integration dialog is such a problem with modal apps in 1.4.2 -- they're sharing (and conflicting with) the same event thread.
    At least this is what I think is happening ~ I'm very sure but cant be 100% certain ..because much like the autodownloads Sun haven't published any of the source for 1.4.2 web start (shouldn't this be part of the shipped sdk source these days?).
    I guess this change breaks your previous class-loading assumptions.
    - Richard

  • Why:current thread not owner?

    Here is my class:
    public class TestThread extends Thread {
        /* (non-Javadoc)
         * @see java.lang.Thread#run()
        @Override
        public void run() {
            System.out.println("begin");
            Test.check();
            System.out.println("end");
    public class Test {
        private static Integer s_count = 0;
        public static void check() {
            synchronized (s_count) {
                while (s_count > 0) {
                    try {
                        s_count.wait();
                        System.out.println("notify");
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
         * @param args
         * @throws InterruptedException
        public static void main(String[] args) throws InterruptedException{
            for (int i = 0; i < 5; i++) {
                s_count++;
                TestThread tt = new TestThread();
                tt.start();
            for (int i = 0; i < 5; i++) {
                Thread.sleep(3000);
                System.out.println(i);
                synchronized (s_count) {
                    s_count--;
                    System.out.println("s_count is:"+s_count);
                    if (s_count == 0) {
                        try {
                            s_count.notifyAll();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    System.out.println("ssss");
    }

    you are incrementing an Integer member var, which means you are creating a new object each time, hence as each thread runs, it is using a variety of different object references. try separating the lock from the counter:
        private static final Object s_lock = new Object();
        private static int s_count = 0;
        synchronized(s_lock) {
          // do your work on s_count
        }

  • Player's position slider (Thread not owner)

    Hi every1,
    I've a thread that sets a slider value with the player's time in secods,but in case the slider Knob is dragged by the user the thread should wait and player's time should be set as per the value dragged by the user.
    But the wait() method is not executing instead it generates IllegalMonitorStateException: current thread not owner exception. Would you help me please?
    My code is:
    //the thread which sets the slider value as the time in second increases
    public void run() {
         while (true) {
                        if (player != null) {
               nano = player.getMediaTime().getSeconds();
              if (dura >nano) {
                  timex = (int)nano;
                        jSlider.setValue(timex);
                     try {
              Thread.currentThread().sleep(1000);
             } catch (InterruptedException ie) {
        }//the method which sets the slider as a user moves the knob of the slider
    jSlider.addChangeListener(new javax.swing.event.ChangeListener() {
                public void stateChanged(javax.swing.event.ChangeEvent evt) {
                   try{
                      if(jSlider.getValueIsAdjusting()){
    player.setMediaTime(new javax.media.Time((double)  
    jSlider.getValue())); 
                    thr.wait();                  }
                   }catch(Exception e){e.printStackTrace();
                      System.out.println("Exception @ jSlider stateChanged : " + e.getMessage() );
            });Thanks!

    The exception is happening because the ChangeListener thread does not own the monitor on "thr" (see the api documentation for Object.wait). That can be fixed by putting it in a synchronized (this) { ... } block.
    However, I see bigger problems. First, recognize that Java is going to call your ChangeEvent code on the event handling thread, so you definitely don't want it to wait. The screen will stop repainting and the user's mouse release event won't be processed, because you will have suspended the thread that handles those things. Second, you should not modify the position of the slider from any thread other than the event handling thread, for reasons documented at [http://java.sun.com/developer/technicalArticles/Threads/swing/]. That article also shows techniques that are safe.
    I don't mean to be discouraging, just wanted to point out a couple more things so you didn't get strange behavior without knowing why! What you are attempting actually requires some multi-threading skill, so study up!
    Cheers,
    Eric

  • FileUpload: Current thread not ownet?

    Hi, I use the common Apache FileUpload lib.
    When i use it on my local server i work!
    But on my NetWare Tomcat server, i got this message:
    Error Message:current thread not owner
    java.lang.IllegalMonitorStateException: current thread
    not owner
    at
    org.apache.commons.fileupload.DefaultFileItem.getUniqueId(DefaultFileItem.java,
    Compiled Code)
    at
    org.apache.commons.fileupload.DefaultFileItem.getTempFile(DefaultFileItem.java:623)
    at
    org.apache.commons.fileupload.DefaultFileItem.getOutputStream(DefaultFileItem.java:563)
    at
    org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java,
    Compiled Code)
    at UploadFile.doPost(UploadFile.java:54)
    Someone got an id�a???
    thx a lot

    Are you using java 1.4 ? And so is your netware server ?
    http://developer.java.sun.com/developer/bugParade/bugs/4776385.html

  • Threads not working together well  !

    Dear People,
    The following line of code gives an error message:
    while(inTray.size() != 0)
    The error message says:
    current thread not owner, Exception in thread "main"
    Thank you for your advice
    Stan

    Dear Dubwai,
    Here is the entire output. (Except for entire list
    t of credits and debits posted by the bank. )
    Start debit of A//C No. 2 : $971 amount: 45
    Start credit of A//C No. 1 : $624 amount: 71
    End credit of A//C No. 1 : $695 amount: 71
    java.lang.IllegalMonitorStateException: current thread
    not owner
         at java.lang.Object.wait(Native Method)
         at java.lang.Object.wait(Object.java:426)
         at stan_ch15p638.Clerk.isBusy(Clerk.java:80)
    at
    stan_ch15p638.TryBankOperation.main(TryBankOperation.j
    va:75)
    End debit of A//C No. 2 : $926 amount: 45
    Start debit of A//C No. 2 : $926 amount: 48
    Exception in thread "main"
    I would post the entire program but the last time I
    did that
    I received a negative response. The error message
    speaks of
    line 75 which is the line posted previously.No it isn't.
    This is what you posted.
    while(inTray.size() != 0)
    In the above stack trace the following appears...
    Clerk.isBusy...
    That is where the problem occurs in your code.

  • Object.wait() & Object.notify() method

    Hi all,
    My question is related to Object.wait() and Object.notify() method which are used by threads. Why these method belongs to Object class and not Thread when they only use by threads ???

    This question represents one of the fundamental concepts of multi-threading as implemented in the Java environment. It is worth clarifying and explaining why probably was this decision mandatory for the language designers. The multi-threading capabilities are built-into the Java language and not external built or imposed to the libraries. What this means that every object that can be instantiated and operated upon by the Java Virtual Machine must be able to possess this behaviour.
    As far as the Thread class itself is concerned, it provides the ability for the Java objects to be treated as being capable of supporting the re-entrant behaviour. When the object resources are being used by multiple threads produced by the re-entrant-capable process i.e. object, each of these threads are competing. The Java environment handle the competition on the object resources by these threads by providing the monitor mechanism, similar to the semaphors in other languages. While the monitors are being acquired or released for implementing the synchronization, the threads enter into the waiting pool, internal to the Java environment. In this scenario, it is clear, that unless the methods can be "invoked" on the objects being monitored, the threads will fail any synchronization.
    The notify() method will allow a given object to be able to wake up a single thread that is waiting on this object's monitor. Similarly, the wait() method allow the given object to cause current thread to wait until another thread invokes the notify() method for this object. Thus, the wait() or notify() methods represent multi-threading capabilities that Java environment implicitly assumes to be the characteristics of every instantiable Java object. The simple semantics of the Object Orientation suggests us that for this to be cleanly and unambiguously implemented, the "ultimate" superclass or root class of the class hierarchy must include these methods in its interface. This way, it becomes easily possible to "inherit" the multi-threading capabilities down to the Java libraries and all Java custom objects.
    Finally, should these methods be included in the interface in the Thread class, every object desirous of possessing these capabilities must "sub-class" the Thread class, which means that the custom objects that need to be multi-threaded must be extended from the Thread class and that the Runnable interface will put up no value. This will defy all the notions of building up an object-oriented Java application with correct object inheritance.

  • Under CentOS 6 x64, Java Thread.sleep()/Object.wait() will be influenced.

    Under CentOS 6 x64, Java Thread.sleep()/Object.wait() will be influenced while changing OS time.
    I found a BUG in java bug list. The bug id is 6311057 with fixed status. But I find it still existing.
    Under CentOS6 x64 platform, on JDK1.6.0_33, the bug still exists.
    But under CentOS5 x64 platform, on same JDK, the problem does not exist.
    Could anyone give me help? Thanks.
    The bug's link is http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6311057
    Edited by: user10222290 on 2012-6-13 下午9:22

    user10222290 wrote:
    One server could want to synchronize it's OS time with another server when they connected each other for some business reasons. I have 3 computers running pretty much continuously with time synchronised from one of the internet time servers. They never seem to be more than about 1/10 th second apart and any time corrections are very very small.
    Some threads have started to run before changing OS time, so these thread's sleep process will be influenced sometime seriously.I understand that but I would only expect this to be a problem when there is a significant change to the OS time. If each server is synchronized to a time server then the time corrections will be very very small.
    If OS time was turned back some days, these thread could not wake up untill some days passed.Agreed but why would the "OS time be turned back some days" ?
    This whole problem seems to me to arise because the servers are not time synchronized. Now I understand that there may be concerns about the security of external time servers but it is easy enough to make one of the local servers a master and act as a time server to the others.
    I have a small server that typically services some 30 or so external clients. I don't have any control over the clients and do not know anything about the setting of their system clocks. The clients send a time signal as part of a heartbeat and from this the server keeps track of the local time on each client and compensates for any difference when writing logs. I have seen this difference as big as 4 months but the compensation corrects it to within about a second. No adjustment of clocks is required for this.
    I still don't see this 'bug' as a serious bug. I just see a design problem to be solved without changing the OS time on any computer. I know this can be done since I do it. The only problem I see is if you want an accuracy of better than about 20 mS but that does not seem to be required for your system.
    Note - if Oracle accept your new bug report it could take years to fix even if lots of people vote for it to be fixed.

  • Is there a way to figure out what the current thread is?

    I've got the following snippet of code:
    // create a new thread. If the current thread is not this new thread, return
    Thread CountDownThread = new Thread("CountDownThread");
    CountDownThread.start();
    if (/*CURRENT THREAD*/.getName() != CountDownThread.getName()) {
         System.out.println ("I'm not CountDownThread. I'm leaving.");
         return;
    // current thread should be new thread. Therefore start the countdown
    CurrTime = InitTime;
    while(CurrTime.charAt(0) != '-') {      // go until current time is negative
         CurrTime = C.countDown();       // returns the current time based on the difference between the initial and elapsed time
         setText(CurrTime);                   // display current time in JLabel
    C.reset();
    setText(C.getCurrTime());What I'm trying to do is get a clock (C) to count down and display the time remaining in a JLabel (this snippet is taken from a method within that very JLabel which I'm extending from javax.swing.JLabel). While it's counting down, I'd like for the program to go off and do other things. Therefore, I'm trying to create a new thread that carries out the task of counting down while the original/main thread moves on to do other things.
    Please have a look at the above code and tell me if I'm on the right track. The one thing I don't know how to do is figure out how to tell which thread the current thread is. I'm assuming that both the new thread and original/main one will execute the if statement, the new one after it returns from start() (which I haven't defined). The original/main one will detect that it is not the new thread and return, whereas the new thread will and go on to the while loop. In the while loop, it will count down the clock until it reaches 0, after which point it will reset it and die.
    If I'm on the right track, all I need to know is how to detect which thread is currently executing. If I'm not on the right track, what would be the best way to do this?

    What? No! No Thread terminates on the return of start(). Those two events are unrelated!Uh... I think you misunderstood what I said.
    I didn't say that CountDownThread terminates upon returning from start() (which is what it sounds like you interpreted from me); I said that the thread that CountDownThread creates terminates once CountDownThread returns from start() (i.e. like any other local variable/object). This, of course, assumes that CountDownThread has a Runnable object on which to call its run() method (am I right?), in which case my code above doesn't create a new thread at all (i.e. CountDownThread.start() is executed within the main/original thread) - am I right?
    No, run() doesn't call start()! That would be stupid.Again, you misunderstood. I shouldn't need to explain this one. A simple reference to an ordinary dictionary on the words 'former' and 'latter' should suffice :)
    Anyway, all joking aside, I have now improved my code and it works! Here's what it looks like:
    ClockJLabel.java
    package MazeMania.clock;
    public class ClockJLabel extends javax.swing.JLabel {
    private Clock C;
    private ClockJLabelsRunnable CJLR;
    public ClockJLabel() {
      C = new Clock();
      CJLR = new ClockJLabelsRunnable();
      setText(C.getCurrTime()); // should be 00:00:00:00
      setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
      // need to figure out how to set the size so that it sticks
      setForeground(new java.awt.Color(255, 0, 0));
      setBackground(new java.awt.Color(0, 0, 0));
      setOpaque(true);
    // starts the clock counting up indefinitely from 0
    public void start() {
      (new Thread(new Runnable() {
        public void run() {
         while(true) setText(C.getElapsedTime());
       })).start();
      //System.out.println("Started clock...");
    // starts the clock counting down from an initial time and runs this count down in a separate thread
    public void countDown(String InitTime) {
      // initialize the clock
      try {C.initClock(InitTime);}
      catch(java.text.ParseException PE) {
       System.out.println(PE.getMessage());
      // initialize JLabel's display
      setText(C.getCurrTime());
      // prepare Runnable and give it to new Thread. New Thread starts count down.
      CJLR.task = CJLR.COUNTDOWN;
      CJLR.CJL = this;
      Thread CountDownThread = new Thread(CJLR);
      CountDownThread.start();
    public Clock getClock() {
      return C;
    }ClockJLabelsRunnable
    package MazeMania.clock;
    import java.lang.Runnable;
    class ClockJLabelsRunnable implements Runnable {
    public static int COUNTDOWN = 1;
    public static int COUNTUP = 2;
    // NOTE: this Runnable doesn't test for the proper setting of these variables
    public int task = 0;
    public ClockJLabel CJL = null;
    public void run() {
      Clock C = CJL.getClock();
      while(C.countDown().charAt(0) != '-') {CJL.setText(C.getCurrTime());}
      C.reset();
      CJL.setText(C.getCurrTime());

  • ORA-04043: object SYS.DELTA$SESSION does not exist

    Dear Friends
    after I import my data by using the follwoing import script :
    IMP JCC/P_MANUF FILE =JCC.DMP FULL
    and at the end give this message import has been imported succesfully without warning
    then when I use this script :
    SQL> SELECT TNAME FROM TAB
    2 WHERE TNAME LIKE 'USER_SESSION'
    3 /
    TNAME
    USER_SESSION
    The table USER_SESSION is exist but when I try to desplay the structure of the USER_SESSION by using this :
    SQL> DESC USER_SESSION
    ERROR:
    ORA-04043: object SYS.DELTA$SESSION does not exist
    and when I try to use the select statment as the following
    SELECT * FROM USER_SESSION
    ERROR at line 1:
    ORA-00980: synonym translation is no longer valid
    Waiting for your valuable answer.
    Best regards
    Jamil Alshaibani

    SQL> select * from V$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE 11.1.0.6.0 Production
    TNS for Linux: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    SQL> !uname -a
    Linux KAD-VMWARE 2.6.9-55.ELsmp #1 SMP Fri Apr 20 16:36:54 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
    SQL> sho user
    USER is "SYS"
    SQL> select object_type,status from dba_objects where object_name = 'K_DRWDWN_GRP' and OWNER = 'SYS';
    no rows selected
    Is any thing wrong with my dictionary? please let me know if i missed anything?
    Edited by: sanora600 on Oct 16, 2010 12:34 AM

  • Will subsequent calls to an object running in a thread run in the thread?

    Hi,
    If I start a thread with an empty run method and then make a call to the object that I started in the thread, will the method call run in the other thread? For example:
    class ThreadClass implements Runnable {
        public void someMethod() {
        public void run() {
    class ThreadCaller {
        private ThreadClass threadClass;
        public ThreadCaller() {
            threadClass = new ThreadClass();
            Thread thread = new Thread(threadClass);
            thread.start();
        public blah() {
            threadClass.someMethod();
    }Will the method call in blah() run in the same thread as ThreadCaller, or will it run in the thread that was started in ThreadCaller's constructor?
    Thanks,
    Dan

    Djaunl wrote:
    vanilla_lorax wrote:
    Djaunl wrote:
    Is there a way to keep the thread alive until the object that started the thread is terminated,Objects don't get terminated. What do you mean?I want the thread to stay alive indefinitely until I arbitrarily terminate it makes more sense. The thread will stay alive until its run method completes. The canonical approaches are
    public void run() {
      while (!Thread.interrupted()) { // NOT isInterrupted()
        // do stuff
        // if you need to catch InterruptedException, do this:
        try {
        catch (InterruptedException exc) {
          Thread.currentThread().interrupt();
    }And then from another thread, call theAboveThread.interrupt() when it's time to stop. Read the docs in interrupt(), interrupted(), the interrupt flag, etc.
    OR
    while (!done()) {
      // do stuff
    }and then another thread calls setDone(true) or somesuch when it's time to stop. Note that all access to done--both get and set--must be synchronized, or done must be declared volatile. Also note that you may still have to handle interrupts, so you may have some repeated code with this approach--testing both done() and interrupted().
    Let me give the end-goal of this.
    Currently, I have a "main" thread which the user can input commands into, and another thread which occasionally runs in the background. When I want something to run in the background, I just create a new thread. However, I figured it'd be more efficient to have one thread running in the background to do something as opposed to spawning hundreds of new threads to do the same task over and over. If the task happens VERY frequently and what it does is VERY small and quick, then the overhead of thread creation may make this a valid approach. Otherwise, don't overcomplicate it. Since you're new to threads, first get it working where you spawn one thread for each background task. Then move on to thread pooling. Look into ThreadPoolExecutor and related classes.
    http://java.sun.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html

  • Need some help killing threads (not in the way already mentioned..)

    I have read the ways in which we should safely kill a thread - and for the most part i understand that. But my question is HOW to implement it in the way that I need.
    Basically I have a multithreaded (ewww) app that really is a large job scheduler running 24/7. It can run anywhere from 1 to 15 jobs at a given time. This is fine. What i need is to have the ability to 'kill' a job when I need to. When the app daemon decides its time to run a certain job (based on business logic) it kicks one off, which is a class I made that implements Runnable.
    public class SchedulerProcessThread extends SOQBase implements Runnable{}
    when its time to start a job i do the usual:
    SchedulerProcessThread spt = new SchedulerProcessThread(blah);
    Thread t = new Thread(spt, "fooname");
    t.start();
    Now, this comes to my problem of where/how to kill the job (if needed). A SchedulerProcessThread is linear and finite so it will always have a termination point - it never loops. And when one is kicked off - i do not have a reference to it anymore - I mean, I couldnt if i am constantly running new jobs, potentially hundreds every hour. And jobs can be started in various places in the app, depending upon whether others are already running, etc.
    I wish to implement the do-while (alive) logic on the job thread. So in the 'run()' method of my SPT class, I would like the:
    while (alive) {
    doProcessing();
    But how can i invoke a method on my class [SPT] so that it changes the alive var from true to false when i do not have a reference to it?
    As a side note, I have a command prompt on the app whereby i can call up all the running 'jobs' which is a list of the running threads under a threadgroup called 'soqjob' (all new Threads that are started with a passing param of and SPT object are under the 'soqjob' threadgroup). So now i can see all those 'soqjob' threads which are currently running Thread objects that have been passed new instances of an SPT class.
    Is there anyway i can grab the 'soqjob' thread of my choice and somehow access my SPT class that was originally passed to it in the Thread constructor? if so, then I could pass in the command to stop the do-while loop.
    Hmm - does any of this make sense? If i can sum up, the problem is i do not know how to access my own SPT class once I have passed it into a thread object and invoked that thread object's 'start()' method. if i can do that, then i can switch the ALIVE var from true to false and thereby kill the SPT job i need.
    Any ideas?
    Many thanks
    Ian

    I would add a Collection (synchronized) to the Scheduler that holds a reference to all the Processes. Pass a reference of the Scheduler to the Processes so that when a Process is done, it can remove itself from the Collection.
    public class Scheduler {
         private Collection threads;
         public void addProcess() {
              Runnable runnable = new ProcessThread(this);
              Thread thread = new Thread(runnable);
              thread.start();
              threads.add(thread);
         public void removeProcess(ProcessThread thread) {
              threads.remove(thread);
         private Thread getSelectedThread(Component c) {
              //Find Thread in Collection and return it
         private class Action implements ActionListener {
              public void actionPerformed(ActionEvent e) {
                   Thread thread = getSelectedThread(e.getSource());
                   thread.interrupt();
    class ProcessThread extends ... implements Runnable {
         private Scheduler scheduler;
         public ProcessThread(Scheduler s) {
              this.scheduler = s;
         public void run() {
              while (!Thread.interrupted()) {
                   try {
                        doProcessing();
                        Thread.yield();     //Give the other Threads a chance to do some work
                   } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
              this.scheduler.removeProcess(this);     //Remove this Thread from the Scheduler's Collection
    }Did you consider using the classes java.util.Timer and java.util.TimerTask?

Maybe you are looking for