thread problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: thread problem

  1. #1
    satish Guest

    thread problem


    Hi I am having problems with this bit of code....

    the wait method is hanging the system..if if say
    syncObj.wait(2000)
    then it works..but there doesnrt seem to be any communication between
    noify() and wait() methods. I am not able to work out about the problem...pls
    do help...

    Regards

    Satish

    private boolean upgradeComplete= false;
    private Object syncObj = new Object();

    if (response == JOptionPane.YES_OPTION)
    {
    depotVersion = JOptionPane.showInputDialog(parent,
    "Please enter the depotVersion:" /*13A*/);
    txtDisplay.append("Performing the OAM Upgrade " +
    '\n');
    // get ats connection, prepare data and send it

    txtOAMVersion.setText(" ");

    // pls check the code from here...................................

    callInvokeOAMUpgrade();

    // this mathod takes a few secs to execute and I want the callCurrentVersion
    to wait for this to complete...


    synchronized(syncObj)
    {

    while(upgradeComplete = false);
    {
    System.out.println(upgradeComplete);
    try
    {
    syncObj.wait(); // I waant this to wait..
    }
    catch (Exception e){ }
    }
    if(upgradeComplete = true)
    {
    System.out.println(upgradeComplete);
    syncObj.notify(); //after completion it notifys
    callCurrentVersion();
    }
    }
    }
    else if (response == JOptionPane.NO_OPTION)
    {
    txtDisplay.append(" OAM Upgrade cancelled" + '\n');
    }
    btnOAMRollback.setEnabled(true);
    btnOAMUpgrade.setEnabled(true);
    }


  2. #2
    Randy Charles Morin Guest

    Re: thread problem

    From what I can tell, you are synchronizing on the object and waiting on it.
    The notify call is also synchronized on the same object as the wait. This
    means that notify will never be called while you are waiting. That is, calls
    to wait and calls to notify are synchronized (only one can be called at any
    time).

    You best solution is to read a bit about synchronization objects in Java.
    --
    Randy Charles Morin
    Author of Programming Windows Services
    http://www.kbcafe.com

    Feel free to contact me by private email or messenger
    MSN Messenger - morin_randy@hotmail.com
    Yahoo Messenger - randymorin@yahoo.com

    "satish" <satish_141@yahoo.com> wrote in message
    news:3c064151$1@147.208.176.211...
    >
    > Hi I am having problems with this bit of code....
    >
    > the wait method is hanging the system..if if say
    > syncObj.wait(2000)
    > then it works..but there doesnrt seem to be any communication between
    > noify() and wait() methods. I am not able to work out about the

    problem...pls
    > do help...
    >
    > Regards
    >
    > Satish
    >
    > private boolean upgradeComplete= false;
    > private Object syncObj = new Object();
    >
    > if (response == JOptionPane.YES_OPTION)
    > {
    > depotVersion = JOptionPane.showInputDialog(parent,
    > "Please enter the depotVersion:" /*13A*/);
    > txtDisplay.append("Performing the OAM Upgrade " +
    > '\n');
    > // get ats connection, prepare data and send it
    >
    > txtOAMVersion.setText(" ");
    >
    > // pls check the code from here...................................
    >
    > callInvokeOAMUpgrade();
    >
    > // this mathod takes a few secs to execute and I want the

    callCurrentVersion
    > to wait for this to complete...
    >
    >
    > synchronized(syncObj)
    > {
    >
    > while(upgradeComplete = false);
    > {
    > System.out.println(upgradeComplete);
    > try
    > {
    > syncObj.wait(); // I waant this to wait..
    > }
    > catch (Exception e){ }
    > }
    > if(upgradeComplete = true)
    > {
    > System.out.println(upgradeComplete);
    > syncObj.notify(); //after completion it

    notifys
    > callCurrentVersion();
    > }
    > }
    > }
    > else if (response == JOptionPane.NO_OPTION)
    > {
    > txtDisplay.append(" OAM Upgrade cancelled" +

    '\n');
    > }
    > btnOAMRollback.setEnabled(true);
    > btnOAMUpgrade.setEnabled(true);
    > }
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center