Results 1 to 4 of 4

Thread: Problems with multiple threads and GUI refresh in Java

  1. #1
    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.

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

Similar Threads

  1. Threads in Java
    By Addis in forum Guides & Tutorials
    Replies: 4
    Last Post: 18-02-2010, 12:47 PM
  2. threads concept in java
    By vijji191 in forum Software Development
    Replies: 2
    Last Post: 30-11-2009, 03:44 PM
  3. Multiple Inheritance in Java
    By KALINDA in forum Software Development
    Replies: 3
    Last Post: 03-11-2009, 07:43 PM
  4. How to refresh data of Jtable in java
    By sarmad_iu in forum Software Development
    Replies: 1
    Last Post: 28-05-2009, 02:45 PM
  5. Refresh Java Applet
    By Brake Fail in forum Software Development
    Replies: 6
    Last Post: 16-03-2009, 10:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,139,888.89505 seconds with 17 queries