[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

need help with swing and multithreading (gui lockup)

Posted on 2003-10-31
4
Medium Priority
?
345 Views
Last Modified: 2011-09-20
I have a multithreaded application and am using swing as my interface.  My threads communicate with each other through queues that are class objects of the base class the threads are derived from.

I want to click a menu item to send a message to one of the threads and wait for a response in the background and then reenable the menu item it has been recieved. I've read the sun doc's and thought i could use invokelater ()., but my gui locks up. cCan anyone help. herses the code

// heres the event handler for menu item
public void actionPerformed(ActionEvent e)
  {

   adaptee.OffHook_actionPerformed(e);
   // disable menu item
   adaptee.OffHook.setEnabled(false);

 
   Runnable doWorkRunnable = new Runnable()
   {
     public void run()
       {
       ProcessConsleMsg ();
       }
    };

  // I thought this would run in background thread
   SwingUtilities.invokeLater (doWorkRunnable);
  }


// sends a message to control queue and waits for response
// console queue
  public void ProcessConsleMsg ()
  {
   Msg zMsg;

   zMsg = new Msg ();
   zMsg.SetMsgType(OFF_HOOK);

   // send message to crontrol task
   ConsleTsk.SendCtrlMsg(zMsg);

    // wait for response to return in consle queue
    // on purpose I'm not send back a response, locking up gui
   // wy doesn't this porocess run in background?
    while (ConsleTsk.ConsleQue.GetMsg()   == null);

    adaptee.OffHook.setEnabled(true);

   }

}
0
Comment
Question by:BlackRussian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9661344
> // I thought this would run in background thread
>  SwingUtilities.invokeLater (doWorkRunnable);

No that says to run it in the swing thread.

You need to wait in a new Thread, and once done then call invokeLater from tyhat thread to notify your gui.
0
 

Author Comment

by:BlackRussian
ID: 9661646
Can you point me to some example code. I was using the bingo example in sun docs.
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 9661663
something like:

public void actionPerformed(ActionEvent e)
  {

   adaptee.OffHook_actionPerformed(e);
   // disable menu item
   adaptee.OffHook.setEnabled(false);

 
   Runnable doWorkRunnable = new Runnable()
   {
     public void run()
       {
       ProcessConsleMsg ();
       }
    };

   new Thread(doWorkRunnable).start();
  }


// sends a message to control queue and waits for response
// console queue
  public void ProcessConsleMsg ()
  {
   Msg zMsg;

   zMsg = new Msg ();
   zMsg.SetMsgType(OFF_HOOK);

   // send message to crontrol task
   ConsleTsk.SendCtrlMsg(zMsg);

    // wait for response to return in consle queue
    // on purpose I'm not send back a response, locking up gui
   // wy doesn't this porocess run in background?
    while (ConsleTsk.ConsleQue.GetMsg()   == null);

    EventQueue.invokeLater(new Runnable()
    {  public void run() { adaptee.OffHook.setEnabled(true); }});

   }

}
0
 
LVL 92

Expert Comment

by:objects
ID: 9661803
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question