Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Problems with multiple threads and GUI refresh in Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-07-2010
Member
 
Join Date: Apr 2010
Posts: 73
Problems with multiple threads and GUI refresh in Java
  

I try to outsource just a little longer lasting function in its own thread (so far tried on Thread, Runnable or Swing workers) to keep the surface during the process to use. The function runs smoothly in the background, now I got the problem that at the end of the run () method, the surface should be redrawn (refresh ()), in order to represent the result of the background function, and since I get so far always an exception:
org.eclipse.swt.SWTException: Invalid thread access

Browsing the Internet I have found some evidence that there may be problems if one tries to change a background thread from the surface or update. Unfortunately, none of it (usually works only sparingly) above alternatives or not matched the rest of the program. I read somewhere that one of the surface suggest a refresh can, which will then (eventually) run from the actual surface thread, but unfortunately was not described how to do it. Now I hope this maybe someone has an idea how this problem could be solved. Please help me to resolve this problem.

Reply With Quote
  #2  
Old 30-07-2010
Member
 
Join Date: Mar 2008
Posts: 258
Re: Problems with multiple threads and GUI refresh in Java

Here time is a code snippet:
Code:
setSearching (true); 

RunSearch = new Runnable Runnable () ( 

@ Override 
public void run () ( 

Entry current = langugeFileManager 
. GetEntryForKey (getCurrentKey ()); 

setSearching (false); 
viewer.refresh (); 

) 

);
The viewer is to be refreshed is a org.eclipse.jface.viewers.TableViewer (I program a EclipsePlugin). If I comment out the refresh line the program runs without error, but then unfortunately no update of the view.
Reply With Quote
  #3  
Old 30-07-2010
Member
 
Join Date: Oct 2008
Posts: 167
Re: Problems with multiple threads and GUI refresh in Java

The Eclipse code book says, "You need the (SWT) Display instance, fire up the runnable asynchronously there.
Code:
RunSearch = new Runnable Runnable () ( 
... 
); 
display.asyncExec (runSearch);
The Swing event queue is not for the SWT.
Reply With Quote
  #4  
Old 30-07-2010
Member
 
Join Date: Jan 2006
Posts: 211
Re: Problems with multiple threads and GUI refresh in Java

It is really the Eclipse objects. Some of these are only by the thread calling problems, which she has created. Since my thread so only after the application accessing it at some point, the access could not be allowed. The solution is relatively simple. I just have the line
Event Queue. InvokeLater (runSearch);
against the line
Display.getCurrent (). AsyncExec (runSearch);
been replaced and the thing runs like it should. The display (org.eclipse.swt.widgets.Display) seems to be the only way to access the objects and asynchronously.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problems with multiple threads and GUI refresh in Java"
Thread Thread Starter Forum Replies Last Post
Threads in Java Addis Guides & Tutorials 4 18-02-2010 12:47 PM
threads concept in java vijji191 Software Development 2 30-11-2009 03:44 PM
Multiple Inheritance in Java KALINDA Software Development 3 03-11-2009 07:43 PM
How to refresh data of Jtable in java sarmad_iu Software Development 1 28-05-2009 02:45 PM
Refresh Java Applet Brake Fail Software Development 6 16-03-2009 10:02 PM


All times are GMT +5.5. The time now is 11:20 AM.