IllegalMonitorStateException problem

er, i'm having a problem with thread in an applet
i'm trying to make it so the thread runs only when the mousedrag() method returns an event, which is that i want the thread to run only while i'm dragging the mouse
using the wait() and notify() methods. but i get a error message saying this:
java.lang.IllegalMonitorStateException: current thread not owner
why is this happening? can anyone teach me the "right" way of implementing a thread using the wait and notify methods completely? i'd appreciate it.
thanx,
kev

You can only call notifyAll(), notify(), or wait()
from within a synchronized block either by using a synchronized method
like
// tries to get the lock for the current object
public synchronized void myMethod()
   while ( something)
     try
        wait();
     catch( InterruptedException ie)
}or by something more strange
public void strangeSynchronization()
   synchronized( synchronizedObject)
      synchronizedObject.doSomething();
      synchronizedObject.notifyAll();

Similar Messages

  • Java.lang.IllegalMonitorStateException problem

    Hi all,
    I'm using Future objects but I'm getting java.lang.IllegalMonitorStateException.
    The stack trace is the following:
    java.util.concurrent.ExecutionException: java.lang.IllegalMonitorStateException: current thread not owner
    [java]      at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:215)
    [java]      at java.util.concurrent.FutureTask.get(FutureTask.java:85)
    [java]      at stock.GUI$1.mouseClicked(GUI.java:168)
    [java]      at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
    [java]      at java.awt.Component.processMouseEvent(Component.java:5491)
    [java]      at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
    [java]      at java.awt.Component.processEvent(Component.java:5253)
    [java]      at java.awt.Container.processEvent(Container.java:1966)
    [java]      at java.awt.Component.dispatchEventImpl(Component.java:3955)
    [java]      at java.awt.Container.dispatchEventImpl(Container.java:2024)
    [java]      at java.awt.Component.dispatchEvent(Component.java:3803)
    [java]      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
    [java]      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
    [java]      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
    [java]      at java.awt.Container.dispatchEventImpl(Container.java:2010)
    [java]      at java.awt.Window.dispatchEventImpl(Window.java:1774)
    [java]      at java.awt.Component.dispatchEvent(Component.java:3803)
    [java]      at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
    [java]      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    [java]      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    [java]      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    [java]      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    [java]      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    [java] Caused by: java.lang.IllegalMonitorStateException: current thread not owner
    [java]      at java.lang.Object.wait(Native Method)
    [java]      at dsm.mrmw.ReadHandler.remoteRead(ReadHandler.java:145)
    [java]      at dsm.mrmw.ReadHandler.call(ReadHandler.java:107)
    [java]      at dsm.mrmw.ReadHandler.call(ReadHandler.java:28)
    [java]      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
    [java]      at java.util.concurrent.FutureTask.run(FutureTask.java:123)
    [java]      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    [java]      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    [java]      at java.lang.Thread.run(Thread.java:595)
    where:
    - the chunk of code in GUI.java is
    try {
       Future<ISharedObject> result = memory.read(address); // the "read" call creates a ReadHandler object to satisfy the request
       try {
         SharedObject value = result.get(3, TimeUnit.SECONDS);   // line 168
         Stock s = (Stock) value.getObject();
       } catch (InterruptedException e1) {
         e1.printStackTrace();
       } catch (ExecutionException e1) {
         e1.printStackTrace();
      } catch (TimeoutException e1) {
         e1.printStackTrace();
    } catch (BadAddressException e1) {
         e1.printStackTrace();
    }while the chunk of code responsible for the exception in ReadHandler, a Callable object, is:
    // the line 107 is the call of this method
    private final ISharedObject remoteRead() throws ReadException,
         DuplicateRequestException {
              try {
                    *  Creates a new destination and stores it into the
                    *  subscriptions hash table.
                   Subscription toSubscribe = subscribe();
                   // Sends "synchronization" request ONLY if this subscription is
                   // not already present.
                   if (subscriptions.putIfAbsent(
                             toSubscribe.destination, toSubscribe) == null) {
                        toSubscribe.sendRequestMsg();
                   if (memory.queueThread(address.toString(), this) == null) {
                        try {
                             wait(timeoutInMillisecs);   // line 145
                        } catch (InterruptedException e) {
                             Thread.currentThread().interrupt();
                        return memory.get(address);
                   // else the request has already been submitted but it's still pending
                   throw new DuplicateRequestException();
              } catch (NamingException e) {
                   if (logger.isEnabledFor(Level.INFO)) {
                        logger.info("Unable to satisfy the remote read request: " +
                                  e.getLocalizedMessage());
                   throw new ReadException();
              } catch (JMSException e) {
                   if (logger.isEnabledFor(Level.INFO)) {
                        logger.info("Unable to satisfy the remote read request: " +
                                  e.getLocalizedMessage());
                   throw new ReadException();
              } finally {
                   memory.removeWaitingThread(address.getDestination());
         }How can I solve this error?
    Best regards,
    Michele

    I'll reply by by own: the solution seems to be making the remoteRead() method synchronized (or to use a synchronized block)

  • Thread problems - illegalMonitorStateException

    Hi,
    I have a problem when I create a thread - I get a illegalMonitorStateException
    My thread is defined :
    MyThread implements Runnable {
    run() {
    while(something !=true) {
    try {
    wait();
    //illegal monitor exception is thrown at wait
    catch(InterruptedEcxception e) {
    //occurs when notified
    doSomething();
    //if operation success, something - true
    //else continue waiting
    I call my thread from a different class as:
    MyThread thread = new MyThread();
    Thread newThread = new Thread(thread);
    thread.start();
    I get illegal monitor state exception.
    Can somebody help me?
    Thankyou,
    Krishna.

    The wait method can only be called from inside of a synchronized block, just make the method from where you want to call the wait method synchronized. BUT I cant see WHY you would want to call the wait method from your run method of your thread; and subsiquently makeing it synchronized.
    There is a diffrence between what your thread object is and what your monitor object is. Your monitor object contains your synchronized code and uses its self as the semaphore to grant diffrent threads to execute its syncronized mehtods.
    Hope this helps
    Regards
    Omer

  • Problem with Threads and a static variable

    I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
    Code functionality:
    A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
    The problem as far I understand is:
    Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
    Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
    Thanks,
    B.D.
    Code:
    private static volatile boolean bChanged = false;
    private static Thread objMainProcess;
       protected static void Init(){
            objMainProcess = new Thread() {
                public void run() {
                    while( objMainProcess == Thread.currentThread() ) {
                       GetState();
            objMainProcess.setDaemon( true );
            objMainProcess.start();
        public static void initStatusTimer(){
            if(objTimer == null)
                 objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
                    public void actionPerformed( java.awt.event.ActionEvent evt){
                              SetState();
        private static void SetState(){
            if( objMainProcess == null ) return;
            synchronized( objMainProcess ) {
                bChanged = true;
                try{
                    objMainProcess.notify();
                }catch( IllegalMonitorStateException e ) {}
        private static boolean GetState() {
            if( objMainProcess == null ) return false;
            synchronized( objMainProcess ) {
                if( bChanged) {
                    SendMessage();
                    bChanged = false;
                    return true;
                try {
                    objMainProcess.wait();
                }catch( InterruptedException e ) {}
                return false;
        }

    Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
    Again as you said, There is a reason I can't call sendMessage() inside setState().
    The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
    Thanks,
    B.D.

  • Problem with Thread in JApplet

    Hi,
    I am working on a project on pseudo random functions, and for that matter I have written a problem. Now I am working on a user interface (JApplet) for my program. Because some heavy calculations can occur, I want to keep track of the progress, and show that in my JApplet. To do so, I start a Thread in which the calculations take place. In my JApplet I want to show every second how far the proces is done. The strange thing is, that the status JLabel only appears when the whole proces is done, and the start button keeps pressed during the proces. If I run this in the applet viewer, I can see the status every second in my command box. You can see the applet here : applet
    The code concerning the start button's actionlistener (entire appletcode: [applet code|http://www.josroseboom.nl/PseudoRandomClusteringApplet.java]) :
              if(e.getSource()==start)
                   int[][] randomFuncties = new int[current+1][5];
                   int puntenHuidige, g, q, y, m, f;
                   boolean done;
                   Kern k;
                   for(int i = 0;i<=current;i++)
                        randomFuncties[i] = functies.getValues();
                   invoer.remove(knopjes);
                   startTijd = System.currentTimeMillis();
                   proces.setBounds(25,(current+4)*25, 2*this.getWidth()/3,75);
                   invoer.add(proces);
                   this.validate();
                   this.repaint();
                   for(int i = 0;i<=current;i++)
                        puntenHuidige = 0;
                        f = randomFuncties[i][0]; // important for instantiation of k, which is cut out here
                        done = false;
                        k.start();     // k is a Thread where heavy calculations are done
                        ((JLabel)(proces.getComponent(2))).setText("points done of current (" + q + ")");
                        this.repaint();
                        while(!done)
                             ((JLabel)(proces.getComponent(1))).setText("" + convertTime(System.currentTimeMillis() - startTijd));
                             ((JLabel)(proces.getComponent(3))).setText("" + k.getPuntenGehad()); // get the point done so far
                             ((JLabel)(proces.getComponent(5))).setText("" + ((100*k.getPuntenGehad())/q) + "%");
                             debug("q: " + q);
                             debug("point done: " + k.getPuntenGehad());
                             if(k.getPuntenGehad()==q)     //if all points are considered
                                  done=true;
                             this.validate();
                             this.repaint();
                             try
                                  Thread.sleep(1000);
                             catch(InterruptedException exception)
                                  debug("foutje met slapen: InterruptedException");
                             catch(IllegalMonitorStateException exception)
                                  debug("foutje met wachten: IllegalMonitorStateException");
                             debug("IN APPLET: yet another loop walk");
                        stringResultaten.add(k.geefResultaat());
                   klaarLabel.setBounds(this.getWidth()/4,(current+8)*25, this.getWidth()/2,25);
                   naarResultaat.setBounds(25+this.getWidth()/4,(current+9)*25, this.getWidth()/4,25);
                   invoer.add(klaarLabel);
                   invoer.add(naarResultaat);
                   this.validate();
                   this.repaint();
    Edited by: Jos on Sep 19, 2007 1:22 AM

    Never do anything that takes more than a fraction of a second in an actionPerformed method or similar GUI callback.
    The GUI stuff is all handled by a single thread called the "AWT Dispatcher" thread. That includes code in such callbacks. While it's executing your callback it can't do any kind of screen updating or response to other user events.
    Instead your actionPerformed should work with a separater "worker" thread, either it should launch a new thread, or release one you create (using wait and notify). Then, it returns without waiting. When the worker thread wants to update the GUI it uses EventQueue.invokeLater() or invokeAndWait() to run some (fast) code on the Dispatcher thread.

  • Problem in connecting to LDAP DS with iPlanet 4.1 Web server

    We have a web application deployed in iPlanet4.0 web server, we are using Sun One directory server for authentication.( Thru JNDI - Package javax.naming.ldap)
    The Problem :
    The problem is that, I am able to do the LDAP related operations anly a few times, after which the below stated exception results. Following this exception, I cannot connect to the directory server again, unless I restart the webserver. For all my operations I establish a fresh context.
    The Exception :
    java.lang.IllegalMonitorStateException: current thread not owner Exception

    Is tghe user id and password that it is requesting for OID? If so then you have several options. You can supply a user DN and password for a know user. For instance, if you have a user DN of cn=jdoe,ou=slaes,o=acme this would be the user is or DN that you need. This DN would have a password attribute associated with it and that would be the password.
    Second, OID has a super user DN called cn=orcladmin. The default password for this su is manager.
    Hope this helps.
    Jay
    null

  • 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

  • Problem connecting weblogic 5.1 to AS400 DB2 version

    Hi All,
    I am having problem connecting from a weblogic server 5.1 version on win2000 machine to AS400 DB2 version using iToolbox jdbc driver "com.ibm.as400.access.AS400JDBCDriver".The following is the weblogic connectionpool :
    weblogic.jdbc.connectionPool.DBPool=\
    url=jdbc:as400://3.3.111.111/MySchema,\
    driver=com.ibm.as400.access.AS400JDBCDriver,\
    loginDelaySecs=10,\
    initialCapacity=1,\
    maxCapacity=10,\
    capacityIncrement=1,\
    allowShrinking=true,\
    shrinkPeriodMins=15,\
    refreshTestMinutes=10,\
    props=user=xxx;password=xxx
    weblogic.allow.reserve.weblogic.jdbc.connectionPool.DBPool=\
    everyone
    I am getting the following exception:
    Fri Jan 28 05:38:16 EST 2005:<E> <JDBC Pool> Failed to create connection pool "DBPool"
    weblogic.common.ResourceException: weblogic.common.ResourceException:
    Could not create pool connection. The DBMS driver exception was:
    java.lang.IllegalMonitorStateException: current thread not owner
         at com.ibm.as400.access.PortMapper.getServerSocket(PortMapper.java:150)
         at com.ibm.as400.access.AS400ImplRemote.signonConnect(AS400ImplRemote.java:1831)
         at com.ibm.as400.access.AS400ImplRemote.signon(AS400ImplRemote.java, Compiled Code)
         at com.ibm.as400.access.AS400.sendSignonRequest(AS400.java:2581)
         at com.ibm.as400.access.AS400.promptSignon(AS400.java, Compiled Code)
         at com.ibm.as400.access.AS400.signon(AS400.java:3375)
         at com.ibm.as400.access.AS400.connectService(AS400.java:821)
         at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:2764)
         at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1040)
         at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java, Compiled Code)
         at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:355)
         at weblogic.jdbc.common.internal.ConnectionEnvFactory.makeConnection(ConnectionEnvFactory.java:146)
         at weblogic.jdbc.common.internal.ConnectionEnvFactory.createResource(ConnectionEnvFactory.java:108)
         at weblogic.common.internal.ResourceAllocator.makeResources(ResourceAllocator.java, Compiled Code)
         at weblogic.common.internal.ResourceAllocator.<init>(ResourceAllocator.java, Compiled Code)
         at weblogic.jdbc.common.internal.ConnectionPool.startup(ConnectionPool.java:330)
         at weblogic.jdbc.common.internal.JdbcInfo.initPools(JdbcInfo.java, Compiled Code)
         at weblogic.jdbc.common.internal.JdbcInfo.startup(JdbcInfo.java:255)
         at weblogic.jdbc.common.internal.JdbcStartup.main(JdbcStartup.java:11)
         at java.lang.reflect.Method.invoke(Native Method)
         at weblogic.t3.srvr.StartupThread.runMain(StartupThread.java:219)
         at weblogic.t3.srvr.StartupThread.doWork(StartupThread.java, Compiled Code)
         at weblogic.t3.srvr.PropertyExecuteThread.run(PropertyExecuteThread.java:62)
    Can anyone let me know is there any problem with connection pool configuration or do i have to make any configuration changes on DB2.Why is it throwing current thread not a owner.
    Pl help.

    Hi Joe,
    Can i use jdk1.3.1 version with weblogic 5.1 version to get rid of this problem or will this change in jvm will effect my existing production applications?
    -thanks
    bharani
    Hi Joe,
    Yes the same code put into jsp scriplet is also
    throwing the error
    "java.lang.IllegalMonitorStateException: current
    thread not owner".It would be really wonderfull if
    you can get some info on the stacktrace.The version
    of jdk we are using is jdk1.2.2, is the problem
    anyway related with the jdk version as the standalone
    program i have tested ran on jdk1.3.1 and jdk1.4
    versions.
    Thanking you in advance,
    -bharani
    bharani noudu wrote:
    Hi Joe,
    Thanks for the quick reply.As per your suggestion
    i
    am able to run a simple 15 line
    standalone program with jdk versions of jdk1.3.1and jdk1.4.1 and jt400.jar in the
    classpath, but i am not able to use the sameconfiguration details in the connection
    pool created in weblogic or the same code pasted
    in
    JSP.Both are throwing the exception
    that "current thread is not a owner".Is thisanything related with the web container
    implementation of weblogic 5.1 or the jdk
    version
    of weblogic 5.1 ?
    Can you please help.I am pasting the code i usedbelow for your reference.
    Hi. If you can put this code in a JSP it throwsthe
    "current thread" exception?
    Even if there's no pool?
    I would contact IBM or post to their newsgroups to
    explain the stacktrace.
    The Driver.connect() call just takes a URL and
    properties (user and password).
    There's nothing a user could do to cause such a
    problem.
    java.lang.IllegalMonitorStateException: current
    thread not owner
    at
    com.ibm.as400.access.PortMapper.getServerSocket(PortMa
    pper.java:150)
    at
    com.ibm.as400.access.AS400ImplRemote.signonConnect(AS4
    00ImplRemote.java:1831)
    at
    com.ibm.as400.access.AS400ImplRemote.signon(AS400ImplR
    emote.java, Compiled Code)
    at
    com.ibm.as400.access.AS400.sendSignonRequest(AS400.jav
    a:2581)
    at
    com.ibm.as400.access.AS400.promptSignon(AS400.java,
    Compiled Code)
    atcom.ibm.as400.access.AS400.signon(AS400.java:3375)
    at
    com.ibm.as400.access.AS400.connectService(AS400.java:8
    21)
    at
    com.ibm.as400.access.AS400JDBCConnection.setProperties
    (AS400JDBCConnection.java:2764)
    at
    com.ibm.as400.access.AS400JDBCDriver.prepareConnection
    (AS400JDBCDriver.java:1040)
    at
    com.ibm.as400.access.AS400JDBCDriver.initializeConnect
    ion(AS400JDBCDriver.java, Compiled Code)
    at
    com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBC
    Driver.java:355)
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class TestDb2 {
         public static void main(String[] args) {
         Connection connection = null;
         try{               
         DriverManager.registerDriver(newcom.ibm.as400.access.AS400JDBCDriver());          
              connection = DriverManager.getConnection
    ("jdbc:as400://1.11.111.1/MySchema","test","test");
              System.out.println("step 1");          
              Statement st = connection.createStatement();          
              System.out.println("step 2");
              ResultSet rs = st.executeQuery("SELECT * FROMMYDB.EMPLOYEE_V");
              while(rs.next()){
                   System.out.println("empid "+rs.getString(1));
              }catch(Exception e){
                   System.out.println("step 3"+e);
                   e.printStackTrace();
              finally{
                   if(connection!=null){
                        try {
                             connection.close();
                        } catch (SQLException e1) {
         e1.printStackTrace();
    Thanking you in advance,
    -bharani
    Hi. That's a very odd internal IBM driver error.
    It's
    mesage is not helpful, and can't be due to
    anything
    you or WebLogic did. Can you get that driver wowork
    on it's own, using it's own example programs? If
    you can get a simple 15-line program to succeed
    making
    a connection, then we can get WebLogic to do the
    same.
    Show me that program and I'll show you the pool
    definition.
    Joe
    bharani noudu wrote:
    Hi All,
    I am having problem connecting from a weblogicserver 5.1 version on win2000 machine to AS400
    DB2
    version using iToolbox jdbc driver
    "com.ibm.as400.access.AS400JDBCDriver".Thefollowing
    is the weblogic connectionpool :
    weblogic.jdbc.connectionPool.DBPool=\
    url=jdbc:as400://3.3.111.111/MySchema,\
    driver=com.ibm.as400.access.AS400JDBCDriver,\
    loginDelaySecs=10,\
    initialCapacity=1,\
    maxCapacity=10,\
    capacityIncrement=1,\
    allowShrinking=true,\
    shrinkPeriodMins=15,\
    refreshTestMinutes=10,\
    props=user=xxx;password=xxx
    weblogic.allow.reserve.weblogic.jdbc.connectionPool.
    DB
    Pool=\
    everyone
    I am getting the following exception:
    Fri Jan 28 05:38:16 EST 2005:<E> <JDBC Pool>
    Failed
    to create connection pool "DBPool"
    weblogic.common.ResourceException:weblogic.common.ResourceException:
    Could not create pool connection. The DBMS
    driver
    exception was:
    java.lang.IllegalMonitorStateException: currentthread not owner
         at
    com.ibm.as400.access.PortMapper.getServerSocket(Port
    Ma
    pper.java:150)
         at
    com.ibm.as400.access.AS400ImplRemote.signonConnect(A
    S4
    00ImplRemote.java:1831)
         at
    com.ibm.as400.access.AS400ImplRemote.signon(AS400Imp
    lR
    emote.java, Compiled Code)
         at
    com.ibm.as400.access.AS400.sendSignonRequest(AS400.j
    av
    a:2581)
         at
    com.ibm.as400.access.AS400.promptSignon(AS400.java,
    Compiled Code)
         at
    com.ibm.as400.access.AS400.signon(AS400.java:3375)
         at
    com.ibm.as400.access.AS400.connectService(AS400.java
    :8
    21)
         at
    com.ibm.as400.access.AS400JDBCConnection.setProperti
    es
    (AS400JDBCConnection.java:2764)
         at
    com.ibm.as400.access.AS400JDBCDriver.prepareConnecti
    on
    (AS400JDBCDriver.java:1040)
         at
    com.ibm.as400.access.AS400JDBCDriver.initializeConne
    ct
    ion(AS400JDBCDriver.java, Compiled Code)
         at
    com.ibm.as400.access.AS400JDBCDriver.connect(AS400JD
    BC
    Driver.java:355)
         at
    weblogic.jdbc.common.internal.ConnectionEnvFactory.m
    ak
    eConnection(ConnectionEnvFactory.java:146)
         at
    weblogic.jdbc.common.internal.ConnectionEnvFactory.c
    re
    ateResource(ConnectionEnvFactory.java:108)
         at
    weblogic.common.internal.ResourceAllocator.makeResou
    rc
    es(ResourceAllocator.java, Compiled Code)
         at
    weblogic.common.internal.ResourceAllocator.<init>(Re
    so
    urceAllocator.java, Compiled Code)
         at
    weblogic.jdbc.common.internal.ConnectionPool.startup
    (C
    onnectionPool.java:330)
         at
    weblogic.jdbc.common.internal.JdbcInfo.initPools(Jdb
    cI
    nfo.java, Compiled Code)
         at
    weblogic.jdbc.common.internal.JdbcInfo.startup(JdbcI
    nf
    o.java:255)
         at
    weblogic.jdbc.common.internal.JdbcStartup.main(JdbcS
    ta
    rtup.java:11)
         at java.lang.reflect.Method.invoke(Native
    Method)
         at
    weblogic.t3.srvr.StartupThread.runMain(StartupThread
    .j
    ava:219)
         at
    weblogic.t3.srvr.StartupThread.doWork(StartupThread.
    ja
    va, Compiled Code)
         at
    weblogic.t3.srvr.PropertyExecuteThread.run(PropertyE
    xe
    cuteThread.java:62)
    Can anyone let me know is there any problem
    with
    connection pool configuration or do i have tomake
    any configuration changes on DB2.Why is itthrowing
    current thread not a owner.
    Pl help.

  • IllegalMonitorStateException on some queries

    Hi,
    Some SELECT statements in my java code consistently cause exceptions and Oracle core dumps.
    Here is one example:
    SELECT COUNT(H.harvest_id) FROM nm_harvest H , nm_messages M WHERE H.msg_uid=M.msg_uid AND M.user_id=1 AND H.harvest_type='foo' AND M.receive_date BETWEEN (TRUNC(SYSDATE, 'IW') -7) AND TRUNC(SYSDATE, 'IW')
    Can anyone see anything wrong with the statement above?
    This is what it throws:
    java.lang.IllegalMonitorStateException: current thread not owner
    at oracle.jdbc.oci8.OCIDBAccess.parseExecuteDescribe(OCIDBAccess.java)
    at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java)
    at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java)
    at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java)
    at com.neomeo.DBL.DBCore.executeNonModQuery(DBCore.java:140)
    at com.neomeo.DBL.DBCore.getCount(DBCore.java:262)
    at com.neomeo.DBL.DBHarvest.getHarvestCount(DBHarvest.java:144)
    at com.neomeo.BL.HarvestService.getHarvestCount(HarvestService.java:119)
    at NMHarvest.getHarvest(NMHarvest.java:276)
    at NMHarvest.harvestView(NMHarvest.java:208)
    at NMHarvest.handle(NMHarvest.java:107)
    at org.webmacro.servlet.WMServlet.doRequest(WMServlet.java:251)
    at org.webmacro.servlet.WMServlet.doGet(WMServlet.java:212)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:499)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
    at org.apache.jserv.JServConnection.processRequest(JServConnection.java:314)
    at org.apache.jserv.JServConnection.run(JServConnection.java:188)
    at java.lang.Thread.run(Thread.java)
    This is Oracle 8.1.5.0.2 on Linux and the oci8 JDBC driver that came with it....
    Any help would be much appreciated!
    Thanks,
    Otis

    Thanks for the reply Sri!
    The restriction on Infocube wouldn't work either because I have a combination of queries I want to allow and prevent on the same InfoProvider.
    That option got me thinking though... I think another solution would be to create a MultiProvider, copy the queries I need to restrict to that new MultiProvider and then use a role based restriction. The only problem would be that my naming convention for Queries uses the InfoProvider as part of the technical name so I would have to change the names of queries too. (Not to mention the process of creating several MPs and copying the Qs)
    The other option you provide sounds feasible. Is it possible to change the owner of a query after creation? is it something you could easily do everytime you want to allow the editing of the Query?
    Let me put this example:
    a. User X creates a query that we want to control so noone can edit it before authorization.
    assuming the option to restrict by query owner:
    b. We change the owner of the query.
    c. The Query needs to be modified. I change the owner again to user X.
    d. After the modification is done, change the owner of the query again.
    Using this scenario I think I could have a pretty decent solution to my need. Do you think it could work? It heavily depends on being able to modify the owner of the query every time I need to edit or restrict its modification.
    Thanks for the time to help me out,
    JD

  • IllegalMonitorStateException on notify()

    I have a ready thread that runs a timer from up to down:
    public void run(){
                        int counter = timeInSeconds;
                        try {
                             if (countDown){
                                  while (counter > 0 && !stop){
                                  if(GestureGuide.isPause()){
                                       try {
                                                 wait();
                                            } catch (InterruptedException e) {
                                                 // TODO Auto-generated catch block
                                                 e.printStackTrace();
                                       text.text = textToPrint + counter;
                                       canvas.repaintCanvas();
                                       Thread.sleep(1000);
                                       counter--;
                                       setTimeLeftInSeconds(counter);
                             text.text = "Done";
                        } catch (InterruptedException e) {
                             if (!stop){
                                  GestureGuideLogger.getApplicationLog().logException(e);
                             text.text = "Stopped";
                        }finally{
                                  canvas.repaintCanvas();
                                  if (listener != null){
                                       if (!PrepareToTest){
                                            listener.timeThreadStopped();
                                       else {
                                            timeForPrepareEnded = true;
    I added "Pause" button to GUI.
    When "Pause" button pressed - I want to stop the timer thread.
    When "Pause" button released - I want to continue the timer thread.
    So I added the following things:
    I changed the TimerThread to:
    public void run(){
                   synchronized (this){
                        int counter = timeInSeconds;
                        try {
                             if (countDown){
                                  while (counter > 0 && !stop){
                                  if(GestureGuide.isPause()){
                                       try {
                                                 wait();
                                            } catch (InterruptedException e) {
                                                 // TODO Auto-generated catch block
                                                 e.printStackTrace();
                                       text.text = textToPrint + counter;
                                       canvas.repaintCanvas();
                                       Thread.sleep(1000);
                                       counter--;
                                       setTimeLeftInSeconds(counter);
                             text.text = "Done";
                        } catch (InterruptedException e) {
                             if (!stop){
                                  GestureGuideLogger.getApplicationLog().logException(e);
                             text.text = "Stopped";
                        }finally{
                             if(!GestureGuide.isPause()){
                                  canvas.repaintCanvas();
                                  if (listener != null){
                                       if (!PrepareToTest){
                                            listener.timeThreadStopped();
                                       else {
                                            timeForPrepareEnded = true;
    And I added another Thread that starts when"Pause" button state is changed to "pressed":
    public abstract class GestureGuideBaseTest......{
    protected TimerThread sleepThread;
         class StopPauseThread extends Thread {
         public void run() {
              synchronized (sleepThread) {
                   if(!GestureGuide.isPause()){
                        notify();
    The problem is, I get IllegalMonitorStateException on notify();
    How can I solve this?

    Well you synchronize on 'sleepThread' but you call notify() on 'this'. I'd expect you to call sleepThread.notify(), but that is without trying to understand what you are trying to do. The javadoc of the notify() method may provide some hints:
    http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#notify%28%29

  • IllegalMonitorStateException Thrown From Synchronized Block

    Greetings,
    We recently had a case where a java.lang.IllegalMonitorStateException was thrown from section of code (in activemq) that I'm 99.9% sure was properly synchronized. Has anyone ever seen this exception thrown when the object whose wait method is being called is currently owened (via. a synchronized block)?
    The code that this exception occurred was in the backport-util-concurrent library. A get method (which is synchronized) call was made to a FutureTask instance which (eventually) calls Object.wait(). This call threw the exception. Below is the FutureTask code.
    public synchronized Object get() throws InterruptedException, ExecutionException
      waitFor();
      return getResult();
    private void waitFor() throws InterruptedException
      while (!isDone())
        wait();
    }And the stack trace on the exception was:
    ERROR - 21/2 08:56:41 - Failed to checkpoint a message store: java.lang.IllegalMonitorStateException - org.apache.activemq.store.journal.JournalPersistenceAdapter 395
    java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:485)
    at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.waitFor(FutureTask.java:267)
    at edu.emory.mathcs.backport.java.util.concurrent.FutureTask.get(FutureTask.java:117)
    at org.apache.activemq.store.journal.JournalPersistenceAdapter.doCheckpoint(JournalPersistenceAdapter.java:386)
    at org.apache.activemq.store.journal.JournalPersistenceAdapter$2.iterate(JournalPersistenceAdapter.java:129)
    at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:117)
    at org.apache.activemq.thread.PooledTaskRunner.access$100(PooledTaskRunner.java:26)
    at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:44)
    at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
    at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
    at java.lang.Thread.run(Thread.java:619)We are running Java 1.6 on solaris (64-bit). If anybody has any feedback on what might have caused this problem it would be appreciated.
    Thanks,
    Corey

    There seem to be some difficult to reproduce bugs in JDK 6 relating to hotspot compilation (and maybe synchronization). A few threads worth checking out:
    http://forum.java.sun.com/thread.jspa?threadID=5251785&tstart=0
    http://forum.java.sun.com/thread.jspa?threadID=5262404&tstart=0
    My own bug report (this one is reproducible): http://www.blinkenbyte.org/jvm/hotspot_bug_reviewid_1085121.html
    Which reminds me, I need to get around to submitting an update to the report.. disabling HotSpot compilation on the problematic method made the problem go away in my case...
    If at all possible to turn this into a test case, please do so and submit a bug report to Sun. Somehow Sun needs to pay attention to this problem, but I haven't even got a bug id on my problem despite it being 100% reproducible.

  • 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

  • IllegalMonitorStateException from StringBuffer.append()

    Hi,
    I am having a not-easily reproducible problem about IllegalMonitorStateException.
    I have an event dispatching Thread that runs fine for roughly 10 hours. But after that "IllegalMonitorStateException" happens
    most of the time from JRE methods like StringBuffer.append() or Hashtable.clear().
    One observation that i had made is that the IllegalMonitorStateException is happening from synchronized methods.
    I have never received this IllegalMonitorStateException from any wait() ot notify() calls in my code.
    Could somebody please help me with this.
    I am using pbp 1.0
    Thanks in advance.

    Thanks "ChuckBing" for the reply
    ChuckBing wrote:
    Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor.
    I understand that IllegalMonitorStateException is thrown normally when we try to do a wait(), notify() or notifyAll() while not holding lock on the same object.
    But here the scenario is different. See the stack trace log.
    java.lang.IllegalMonitorStateException: current thread not owner
         at java.lang.StringBuffer.append(I)Ljava/lang/StringBuffer;(Unknown Source)
         at java.lang.Thread.startup(Z)V(Unknown Source)
    The exception came from append() method of StringBuffer class. I went through the source code of the StringBuffer class and found the append() method's implementation as
    public synchronized StringBuffer append(String str) {
         if (str == null) {
         str = String.valueOf(str);
         int len = str.length();
         int newcount = count + len;
         if (newcount > value.length)
         expandCapacity(newcount);
         str.getChars(0, len, value, count);
         count = newcount;
         return this;
    So the situation is that an IllegalMonitorStateExceptiion is being thrown from a synchronized method where there are no wait(), notify() or notifyAll() being used.
    Other than wait(), notify() or notifyAll(), what other Java programming mistake can cause such an Exception to be thrown?

  • Facing IllegalMonitorStateException

    Dear forum,
    Facing a problem if IllegalMonitorStateException although I used
    wait & notifyAll in a synchronized block but still the problem persists.
    I am trying to exhibit the synchronized usage.
    MainPlayThread.java
    //Fibonacci series
    public class MainPlayThread extends Thread{
         int count=0;
        int[] j= new int[100];
        private Object lock=null;
        private Object obj = null;
        public MainPlayThread(int count){
             lock = new Object();
             obj = new Object();
              setCount(count);
              start();          
        public synchronized void  run(){         
           try {
                obj=null;      
             Object o = new Object();         
                j[0]=1;j[1]=1;
            int l=0;
            if(count<2)
                 System.out.print(j[0]);
            else
                 System.out.print(j[0]+","+j[1]);
                 for(int k=1;k<=count-2;k++){
                      l=j[k-1]+j[k];
                      j[k+1]=l;
                      System.out.print(","+j[k+1]);
                      Thread.sleep(2000);
             obj=o;
                 lock.notifyAll();
           }catch(Exception e){
                System.out.println();
                System.out.println("Error>>"+e+e.getCause());
                obj=null;
        public void setCount(int c) {
            try{             
                 synchronized(lock){
                      while(obj==null)
                           lock.wait();                  
                      count = c;             
            }catch(InterruptedException ie){
                 System.out.println(ie);
    User1MainPlayThread.Java
    public class User1MainPlayThread {
         public static void main(String[] args)  {
                   MainPlayThread mpt1 =new MainPlayThread(10);
                   MainPlayThread mpt2 =new MainPlayThread(10);
    }The o/p of it says sth like
    1,1,21,1,2,3,3,5,5,8,8,13,13,21,21,34,34,55,55
    Error>>java.lang.IllegalMonitorStateException: current thread not ownernull
    Error>>java.lang.IllegalMonitorStateException: current thread not ownernull

    Hi,
    You are not sychronizing on "lock" before calling
    notifyAll(). PLease use the following code snippet
    at notifyAll().
    code]
    synchronized(lock){
    lock.notifyAll();
    Thanks a lot . It has been rectified .
    One thing more I want to know why I am getting <B>1,1,21</B>,1,2,3,3,5,5,8,8,13,13,21,21,34,34,55,55?

  • A problem with threads

    I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
    Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
    My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
    Thank you in advance,
    Lefty

    This was one solution from the socket programming forum, have you tried this??
    public Thread MyThread extends Thread{
         boolean active = true;          
         public void run(){
              ss.setSoTimeout(90);               
              while (active){                   
                   try{                       
                        serverSocket = ss.accept();
                   catch (SocketTimeoutException ste){
                   // do nothing                   
         // interrupt thread           
         public void deactivate(){               
              active = false;
              // you gotta sleep for a time longer than the               
              // accept() timeout to make sure that timeout is finished.               
              try{
                   sleep(91);               
              }catch (InterruptedException ie){            
              interrupt();
    }

Maybe you are looking for

  • How to set file name and destination folder without user interaction

    how can I set the file name and destination folder to generate a pdf file like "c:\myfolder\document.pdf" in this folder automatically. Is there a tag in .joboptions ? Goal: User click print button. In the background a pdf will be generated in e.g. "

  • Firefox does not create a pdf properly using "print Save as pdf" in Mac OSX. Why?

    When I "Print > Save As Pdf" in Mac OSX, Firefox will always clip the right margin of the page, leaving out alot of information from the document. Safari creates the same page effortlessly, but I generally prefer Firefox. == This happened == Every ti

  • LST CST IN CIN

    Hi Have defined ZTAXIN and assigned to country. later maintained tax codes A0 Output nill tax, A1 input nill tax and left feilds blank .  Then created condition records for BED, AED and LST, CST. Factory and depot plants are in maharashtra, so LST ha

  • Contains pattern syntax in abap

    Hi, I want to check inside loop of itab ,whether my field f1(132) type c contains value '####',if it is true i have to code continue.so i created one var f2 like this data:f2(20) type c value '########'. my code: loop at itab. if f1 cp f2. continue.

  • Upgrade from 3.4 to 4

    Hi, I got the Ligthroom 3.4 Version as a birthday gift in april. How can I get the free upgrade? Can I still get the free Upgrade? I searched everywhere, but I don't know how to contact the customer support. Thanks for your help. Ben