Home » Eclipse Projects » Rich Client Platform (RCP) » Threading strategies in RCP(One Thread with massive Display.syncExec or Threads for every task where SWT is not concerned?)
Threading strategies in RCP [message #1017791] |
Tue, 12 March 2013 10:48  |
Eclipse User |
|
|
|
Hello,
I have an org.eclipse.ui.ISelectionListener, which does some non ui processes and afterwards it builds the UI according to the ISelection.
The Problem is when the user for instance navigates a tree with the cursor keys the selectionChanged event is fired a couple of times and the UI hangs up for a few seconds, because of the processes in the ISelectionListener.
Therefore I wanted to use a delay, until the processes will start and abort the processing, if the selection has changed meanwhile.
This works great:
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// wait half a second and then check if threadId is still current to trigger the actual process
DelayedSelectionChanged delayedSelectionChanged = new DelayedSelectionChanged(
this, threadId, part, selection);
executorService.schedule(delayedSelectionChanged, 500,
TimeUnit.MILLISECONDS);
}
Of cause in between "Invalid Thread Access Exceptions" are thrown.
What would you suggest?
Should I directly use the Display.syncExec() method after the half second to avoid these Exceptions and then again build more threads for the processing?
Should I call every time SWT is used within the Process Display.syncExec()?
I mean how performance consuming is it, when you pass several Runnables to the Display.syncExec() during the process?
Best regards,
Simon
|
|
|
Re: Threading strategies in RCP [message #1017817 is a reply to message #1017791] |
Tue, 12 March 2013 11:40   |
Eclipse User |
|
|
|
On 2013-03-12 15:48, Simon SSC wrote:
> Hello,
>
> I have an org.eclipse.ui.ISelectionListener, which does some non ui
> processes and afterwards it builds the UI according to the ISelection.
>
> The Problem is when the user for instance navigates a tree with the
> cursor keys the selectionChanged event is fired a couple of times and
> the UI hangs up for a few seconds, because of the processes in the
> ISelectionListener.
>
> Therefore I wanted to use a delay, until the processes will start and
> abort the processing, if the selection has changed meanwhile.
Understandable.
> This works great:
>
> @Override
> public void selectionChanged(IWorkbenchPart part, ISelection
> selection) {
> // wait half a second and then check if threadId is still
> current to trigger the actual process
> DelayedSelectionChanged delayedSelectionChanged = new
> DelayedSelectionChanged(
> this, threadId, part, selection);
> executorService.schedule(delayedSelectionChanged, 500,
> TimeUnit.MILLISECONDS);
> }
>
>
> Of cause in between "Invalid Thread Access Exceptions" are thrown.
>
> What would you suggest?
I have no idea what the constructor of DelayedSelectionChanged does, so
my advice can only be limited.
> Should I directly use the Display.syncExec() method after the half
> second to avoid these Exceptions and then again build more threads for
> the processing?
I don't see any reason for any synchronization with the UI thread
between the calls, (but I also don't know precisely what the first call
does).
> Should I call every time SWT is used within the Process Display.syncExec()?
You mean thread, not process, right? I would always call
Display.asyncExec() within the non-UI thread. Display.syncExec() is
generally susceptible to dead-locks and I stay away from it if possible.
I also would try to minimize the number of thread switches within the
delayed worker thread.
HTH & Greetings from Bremen,
Daniel Krügler
|
|
| |
Re: Threading strategies in RCP [message #1021913 is a reply to message #1017791] |
Wed, 20 March 2013 19:12  |
Eclipse User |
|
|
|
Hi Simon,
You can register your listener with the AddPostSelectionListener method. This
has the delay build in.
Best Regards,
Wim
> Hello,
>
> I have an org.eclipse.ui.ISelectionListener, which does some non ui
processes and afterwards it builds the UI according to the ISelection.
>
> The Problem is when the user for instance navigates a tree with the cursor
keys the selectionChanged event is fired a couple of times and the UI hangs
up for a few seconds, because of the processes in the ISelectionListener.
>
> Therefore I wanted to use a delay, until the processes will start and abort
the processing, if the selection has changed meanwhile.
>
> This works great:
>
>
>
> @Override
> public void selectionChanged(IWorkbenchPart part, ISelection selection) {
> // wait half a second and then check if threadId is still current to
trigger the actual process
> DelayedSelectionChanged delayedSelectionChanged = new
DelayedSelectionChanged(
> this, threadId, part, selection);
> executorService.schedule(delayedSelectionChanged, 500,
> TimeUnit.MILLISECONDS);
>
> }
>
>
> Of cause in between "Invalid Thread Access Exceptions" are thrown.
>
> What would you suggest?
>
> Should I directly use the Display.syncExec() method after the half second
to avoid these Exceptions and then again build more threads for the
processing?
> Should I call every time SWT is used within the Process Display.syncExec()?
>
> I mean how performance consuming is it, when you pass several Runnables to
the Display.syncExec() during the process?
>
> Best regards,
>
> Simon
|
|
|
Goto Forum:
Current Time: Wed Mar 26 18:38:41 EDT 2025
Powered by FUDForum. Page generated in 0.03785 seconds
|