-
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);
}
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks