Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Multi-Threaded Applications
Multi-Threaded Applications [message #448930] Fri, 14 January 2005 23:01 Go to next message
Eclipse UserFriend
Originally posted by: shaffin.email.uophx.edu

This is a multi-part message in MIME format.

------=_NextPart_000_0022_01C4FA63.20796730
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello All,

I have an application built using SWT. I have a time consuming Thread =
process as follows:

public class ExpandThread_C extends Thread
{
final private Display __display;
final private Shell __window;
final private ProgressBar __progress;

/**
* Constructor
*/
public ExpandThread_C( final Shell window, ProgressBar progress )
{
super();
this.__display =3D window.getDisplay();
this.__window =3D window;
this.__progress =3D progress;
}

/**
* Run process
*/
public void run()
{
//Update the progress
updateProgress();
this.__window.update(); // this doesnt update the application =
window
this.__window.redraw(); // nor does this doesnt update the =
application window
}

/**
* Update progress
*/
public void updateProgress()
{
__display.syncExec(
new Runnable()=20
{
public void run()=20
{
this.__progress.setSelection(1);
}
}
); =20
}

}

In my application I call the Thread using the BusyIndication class as =
follows:

BusyIndicator.showWhile( shell.getDisplay(), new ExpandThread_C( shell, =
progress ) );

The problem I have is that the process takes almost 3-4 minutes and =
during the time if I minimize and maximize the application window, my =
application is locked up!!! Am I missing something or is this not the =
correct way to run the thread? I want my application window to always be =
available and responsive to the user, any suggestions and/or feedback is =
greatly appreciated.

Thank you,
Shaffin.

------=_NextPart_000_0022_01C4FA63.20796730
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hello All,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I have an application built using SWT. I have a time =
consuming=20
Thread process as follows:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D1><STRONG>public class ExpandThread_C extends=20
Thread<BR>{<BR>&nbsp;&nbsp;&nbsp; final private Display=20
__display;<BR>&nbsp;&nbsp;&nbsp; final private Shell=20
__window;<BR>&nbsp;&nbsp;&nbsp; final private ProgressBar=20
__progress;<BR></STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG>&nbsp;&nbsp;&nbsp; =
/**<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
*&nbsp;Constructor<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; =
public=20
ExpandThread_C( final Shell window, ProgressBar progress =
)<BR>&nbsp;&nbsp;&nbsp;=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
super();<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; this.__display =
=3D=20
window.getDisplay();<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
this.__window=20
=3D window;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
this.__progress =3D=20
progress;<BR>&nbsp;&nbsp;&nbsp; }</STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG></STRONG></FONT>&nbsp;</DIV>
<DIV><FONT size=3D1><STRONG>&nbsp;&nbsp;&nbsp; =
/**<BR>&nbsp;&nbsp;&nbsp;&nbsp; *=20
Run process<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; public =
void=20
run()<BR>&nbsp;&nbsp;&nbsp; {</STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
//Update the=20
progress</STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
updateProgress();</STRONG></FONT></DIV>
<DIV><FONT size=3D1>
<DIV><FONT size=3D1><STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
this.__window.update(); // this doesnt update the application=20
window</STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
this.__window.redraw(); // nor does this doesnt update the application=20
window</STRONG></FONT></DIV><STRONG>&nbsp;&nbsp;&nbsp; =
}</STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG></STRONG></FONT>&nbsp;</DIV>
<DIV><FONT size=3D1><STRONG>&nbsp;&nbsp;&nbsp; =
/**<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
*&nbsp;Update progress<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
*/<BR>&nbsp;&nbsp;&nbsp;=20
public void updateProgress()<BR>&nbsp;&nbsp;&nbsp; =
{</STRONG></FONT></DIV>
<DIV><FONT size=3D1><STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;=20
__display.syncExec(<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;=20
new Runnable()=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;=20
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;=20
public void run()=20
<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;=20
{<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
this.__progress.setSelection(1);</STRONG></FONT></DIV>
<DIV><FONT=20
size=3D1><STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;=20
}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; );&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; }</STRONG></FONT></DIV>
<DIV><STRONG><FONT size=3D1></FONT></STRONG>&nbsp;</DIV>
<DIV><FONT size=3D1><STRONG>}</STRONG></FONT></DIV><FONT size=3D2>
<DIV><BR>In my application I call the Thread using the BusyIndication =
class as=20
follows:</DIV>
<DIV>&nbsp;</DIV>
<DIV><STRONG><FONT size=3D1>BusyIndicator.showWhile( shell.getDisplay(), =
new=20
ExpandThread_C( shell,&nbsp;progress ) );</FONT></STRONG></DIV>
<DIV>&nbsp;</DIV>
<DIV>The problem I have is that the process takes almost 3-4 minutes and =
during=20
the time if I minimize and maximize the application window, my =
application is=20
locked up!!! Am I missing something or is this not the correct way to =
run the=20
thread? I want my application window to always be available and =
responsive to=20
the user, any suggestions and/or feedback is greatly appreciated.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thank you,<BR></FONT><FONT size=3D2>Shaffin.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0022_01C4FA63.20796730--
Re: Multi-Threaded Applications [message #449104 is a reply to message #448930] Tue, 18 January 2005 15:20 Go to previous messageGo to next message
Philip Borlin is currently offline Philip BorlinFriend
Messages: 17
Registered: July 2009
Junior Member
SHAFFIN BHANJI wrote:

> The problem I have is that the process takes almost 3-4 minutes and during
the time if I minimize and maximize the application window, my application is
locked up!!! Am I missing something or is this not the correct way to run the
thread? I want my application window to always be available and responsive to
the user, any suggestions and/or feedback is greatly appreciated.


Try using the job API. Make a class that extends Job (there is only one
method to override) and then call job.schedule to get it to run. Check
out the article
http://eclipse.org/articles/Article-Concurrency/jobs-api.htm l

-Phil
Re: Multi-Threaded Applications [message #449126 is a reply to message #448930] Tue, 18 January 2005 15:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: joerg.von.frantzius.artnology.nospam.com

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
SHAFFIN BHANJI schrieb:
<blockquote cite="midcs9j11$lpp$1@www.eclipse.org" type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta content="MSHTML 6.00.2900.2180" name="GENERATOR">
<style></style>
<div><font size="1"><strong><br>
&nbsp;&nbsp;&nbsp; public void updateProgress()<br>
&nbsp;&nbsp;&nbsp; {</strong></font></div>
<div><font size="1"><strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; __display.syncExec(<br>
</strong></font></div>
</blockquote>
Did you try using asyncExec here? I think you are tying the UI to your
background thread, not being able to do anything else. Here's what the
online help says:<br>
<ul>
<li><strong><span><span
style="background: highlight none repeat scroll 0%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; color: highlighttext;">asyncExec</span>(Runnable)</span></strong >
should be used when the application needs to perform some UI
operations, but is not dependent upon the operations being completed
before continuing. For example, a background thread that updates a
progress indicator or redraws a window could request the update
asynchronously and continue with its processing. In this case, there is
no guaranteed relationship between the timing of the background thread
and the execution of the runnable. </li>
</ul>
..<br>
<blockquote cite="midcs9j11$lpp$1@www.eclipse.org" type="cite">
<div><font size="1"><strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new Runnable() <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public void run() <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.__progress.setSelection(1);</strong></font></div>
<div><font size="1"><strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; );&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; }</strong></font></div>
<div><strong></strong>&nbsp;</div>
<div><font size="1"><strong>}</strong></font></div>
<font size="2"></font>
<div><font size="2"><br>
In my application I call the Thread using the BusyIndication class as
follows:</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2"><strong><font size="1">BusyIndicator.showWhile(
shell.getDisplay(), new ExpandThread_C( shell,&nbsp;progress ) );</font></strong></font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">The problem I have is that the process takes
almost 3-4 minutes and during the time if I minimize and maximize the
application window, my application is locked up!!! Am I missing
something or is this not the correct way to run the thread? I want my
application window to always be available and responsive to the user,
any suggestions and/or feedback is greatly appreciated.</font></div>
<div><font size="2">&nbsp;</font></div>
<div><font size="2">Thank you,<br>
</font><font size="2">Shaffin.</font></div>
<div>&nbsp;</div>
</blockquote>
<br>
</body>
</html>
Re: Multi-Threaded Applications [message #449133 is a reply to message #448930] Tue, 18 January 2005 16:24 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.us.NO_SPAM.ibm.com

Thread implements Runnable but it really shouldn't. Many people think
that just doing new Thread, and calling its run method means that the
thread is actually running. That is not correct. One should never call
the run() method themselves. It really should be a protected method in
thread, not a public one. The thread call run when it is started. One
must start the thread, and then it will go off and run itself in a
different thread.

What happened with

> *BusyIndicator.showWhile( shell.getDisplay(), new ExpandThread_C(
> shell, progress ) );*

is that you simply called the run() method within ExpandThread, but the
run() is executing on the UI thread.

Also, showWhile DOES NOT make your UI responsive. All it does is turn on
the Busy cursor while you Runnable is running in the UI thread.

You actually don't need to specify a thread yourself, you can instead
supply a IRunnableWithProgress to Eclipse and it will do it for you.
If you want to run your thread AND have a progress monitor display up
AND have your UI responsive AND not allow any changes to the window
while your thread is running you should use instead:

PlatformUI.getWorkbench().getProgressService().busyCursorWhi le(new
IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws
InvocationTargetException, InterruptedException {
.. put your code that you want to run in a different thread here..

This will show a busy cursor for 800MSecs, then put up a progress
monitor dialog, all the while the contents of the IRunnableWithProgress
run() method will be executing in a different non-UI thread.

Note: The busyCursorWhile() must be called on a ui thread originally.


--
Thanks,
Rich Kulp
Previous Topic:SWT Shell changed behavior in Eclipse 3.1?
Next Topic:Help, Launching HTML in external browser
Goto Forum:
  


Current Time: Thu Nov 21 10:42:20 GMT 2019

Powered by FUDForum. Page generated in 0.01742 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top