J
johnmmcparland
Hi all,
is there some way I can get my main thread to perform an action whilst
waiting on another to finish executing?
e.g.
while (!someObj.finishedLoading())
{
setCursor(Cursor.WAIT_CURSOR);
sleep(1000);
}
where someObj was initialised in a separate thread earlier on?
public class Example
{
// Has to be static and is some sort of chunky GUI
private static SomeObj someObj = null;
private JButton button = new JButton("Start");
public Example()
{
(new Thread(SomeObjRunner())).start();
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
// By now someObj needs to be fully
initialised
someObj.setVisible(true);
}
});
button.setEnabled(false);
waitOnAction();
}
private class SomeObjRunner implements Runnable
{
public void run()
{
someObj = new SomeObj();
}
}
public void waitOnAction()
{
// This is where I need to wait on someObj completing
while (!someObj.isFinished())
{
setCursor(Cursor.WAIT_CURSOR);
sleep(1000);
}
button.setEnabled(true);
}
}
The problem I'm currently having is that the button is enabled when
the someObj is still null.
is there some way I can get my main thread to perform an action whilst
waiting on another to finish executing?
e.g.
while (!someObj.finishedLoading())
{
setCursor(Cursor.WAIT_CURSOR);
sleep(1000);
}
where someObj was initialised in a separate thread earlier on?
public class Example
{
// Has to be static and is some sort of chunky GUI
private static SomeObj someObj = null;
private JButton button = new JButton("Start");
public Example()
{
(new Thread(SomeObjRunner())).start();
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
// By now someObj needs to be fully
initialised
someObj.setVisible(true);
}
});
button.setEnabled(false);
waitOnAction();
}
private class SomeObjRunner implements Runnable
{
public void run()
{
someObj = new SomeObj();
}
}
public void waitOnAction()
{
// This is where I need to wait on someObj completing
while (!someObj.isFinished())
{
setCursor(Cursor.WAIT_CURSOR);
sleep(1000);
}
button.setEnabled(true);
}
}
The problem I'm currently having is that the button is enabled when
the someObj is still null.