Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SwingWorker equivalent in SWT
SwingWorker equivalent in SWT [message #459076] Mon, 01 August 2005 09:19 Go to next message
mohit is currently offline mohitFriend
Messages: 24
Registered: July 2009
Junior Member
Hi All,

I need to put my heavy GUI processes in a separate thread. I heard that
Swing has a SwingWorker class dedicated for the same. Do SWT also provides
some or other thing to achieve this cause?

Thanks,
Mohit
Re: SwingWorker equivalent in SWT [message #459079 is a reply to message #459076] Mon, 01 August 2005 12:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Mohit" <mohit.jhawar@gmail.com> wrote in message
news:d654cd64e704fbf4a35be16c85d60645$1@www.eclipse.org...
> Hi All,
>
> I need to put my heavy GUI processes in a separate thread. I heard that
> Swing has a SwingWorker class dedicated for the same. Do SWT also provides
> some or other thing to achieve this cause?
>
SWT only allows UI updates in the UI thread. So I don't know how much use
your separate thread will be- unless it is also a UI thread (in which case
it will use a separate Display, etc., from the main UI thread- which may not
even be allowed by the platform). From the SWT javadocs:
"Applications which are built with SWT will almost always require only a
single display. In particular, some platforms which SWT supports will not
allow more than one active display. In other words, some platforms do not
support creating a new display if one already exists that has not been sent
the dispose() message. "
---
Sunil
Re: SwingWorker equivalent in SWT [message #459080 is a reply to message #459076] Mon, 01 August 2005 13:08 Go to previous messageGo to next message
Philip  Koester is currently offline Philip KoesterFriend
Messages: 20
Registered: July 2009
Junior Member
> I need to put my heavy GUI processes in a separate thread. I heard that
> Swing has a SwingWorker class dedicated for the same. Do SWT also provides
> some or other thing to achieve this cause?

I don't know if SWT or JFace offer special classes for that, but a basic
approach would be

display.asyncExec(new Runnable() {
public void run() {
doTheJob();
}
} );

Note that you need a reference for the *UI thread's* display. Also, you
might want to use org.eclipse.swt.custom.BusyIndicator. Check out this
example:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet130.java?rev=HEAD& amp;content-type=text/vnd.viewcvs-markup .

Ph.
Re: SwingWorker equivalent in SWT [message #459081 is a reply to message #459080] Mon, 01 August 2005 13:21 Go to previous messageGo to next message
Philip  Koester is currently offline Philip KoesterFriend
Messages: 20
Registered: July 2009
Junior Member
Oops, I might be wrong there. The general idea should be to perform the
operation in a separate thread, just as you said. Anyway, I hope the example
is helpful.

Ph.
Re: SwingWorker equivalent in SWT [message #459086 is a reply to message #459076] Mon, 01 August 2005 16:13 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Mohit wrote:
> Hi All,
>
> I need to put my heavy GUI processes in a separate thread. I heard that
> Swing has a SwingWorker class dedicated for the same. Do SWT also
> provides some or other thing to achieve this cause?
>
> Thanks,
> Mohit
>
Hello,

basically you can copy the construction of SwingWorker simply exchange
all calls to SwingUtilities.invokeLater or EventQueue.invokeLater to
Display.asyncExec
I have not tried this but looking at SwingWorker it is not using any
swing specific code besides the above mentioned methods.

Hope that helps

Regards
Stefan
Re: SwingWorker equivalent in SWT [message #459108 is a reply to message #459081] Tue, 02 August 2005 08:47 Go to previous messageGo to next message
mohit is currently offline mohitFriend
Messages: 24
Registered: July 2009
Junior Member
Yeah, the examples was insightful. However as pointed out by you we need a
separate thread here..which has to be a UI thread. A UI thread requires a
display to run, since SWT doesnt allow more than one display for
application, this thread will share the current display and hence the
whole purpose of threading will go for a toss.

Mohit
Philip Köster wrote:

> Oops, I might be wrong there. The general idea should be to perform the
> operation in a separate thread, just as you said. Anyway, I hope the example
> is helpful.

> Ph.
Re: SwingWorker equivalent in SWT [message #459110 is a reply to message #459108] Tue, 02 August 2005 09:26 Go to previous messageGo to next message
Philip  Koester is currently offline Philip KoesterFriend
Messages: 20
Registered: July 2009
Junior Member
Why would it go for a toss? Do what you want to do in your own separate
thread. Only caveat is when you update anything UI-related you need to use
display.syncExec() from within your thread. And for a more elaborate
approach, I'd not create a new thread every time a longer operation needs to
be done but rather employ a job queue which is waiting for a new task when
idle and automatically updates the UI upon finishing a task.

Ph.
Re: SwingWorker equivalent in SWT [message #459141 is a reply to message #459110] Tue, 02 August 2005 13:53 Go to previous messageGo to next message
mohit is currently offline mohitFriend
Messages: 24
Registered: July 2009
Junior Member
Thanks a lot Philip. I was actually putting the whole process inside
syncExec().

:)
Philip Köster wrote:

> Why would it go for a toss? Do what you want to do in your own separate
> thread. Only caveat is when you update anything UI-related you need to use
> display.syncExec() from within your thread. And for a more elaborate
> approach, I'd not create a new thread every time a longer operation needs to
> be done but rather employ a job queue which is waiting for a new task when
> idle and automatically updates the UI upon finishing a task.

> Ph.
Re: SwingWorker equivalent in SWT [message #459145 is a reply to message #459141] Tue, 02 August 2005 14:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Mohit" <mohit.jhawar@gmail.com> wrote in message
news:ba2ccc6a71af402488cbd80c0cfa9420$1@www.eclipse.org...
> Thanks a lot Philip. I was actually putting the whole process inside
> syncExec().
>
> :)

Also consider using UIJob.
That way, if two GUI modifications of the same type occur in quick
succession, you can cancel the first UIJob and run just the second one.
---
Sunil
Re: SwingWorker equivalent in SWT [message #459290 is a reply to message #459076] Thu, 04 August 2005 23:41 Go to previous message
No real name is currently offline No real nameFriend
Messages: 97
Registered: July 2009
Member
In essence, display is IO device and thus very slow to perform. So there is
no gain with multiple threads. If you have to use multiple threads for
number crunching or other requirement, you can achieve the same thing with
normal synchronization. For example, you can have synch objects and
serialized all display operation inside it;

compute;
synchronizeed (obs) {
check display status and if display is needed then modify display
contents;
}

Regards.


"Mohit" <mohit.jhawar@gmail.com> wrote in message
news:d654cd64e704fbf4a35be16c85d60645$1@www.eclipse.org...
> Hi All,
>
> I need to put my heavy GUI processes in a separate thread. I heard that
> Swing has a SwingWorker class dedicated for the same. Do SWT also provides
> some or other thing to achieve this cause?
>
> Thanks,
> Mohit
>
Previous Topic:roadmap for SWT??
Next Topic:SWT newbie question
Goto Forum:
  


Current Time: Fri Apr 19 19:40:49 GMT 2024

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

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

Back to the top