Viewpart에서 외부library 사용중 그 라이브러리에서도 내부적으로 쓰레드를 사용하여 충돌이 발생한듯 하다.

 

안드로이드 같은경우 main 스레드와 UI 스레드가 따로 구분되어 있다.

SWT역시 그러한듯 하다. 그렇게 만들어져야만 한다.

 

Text text;

text.getDisplay().asyncExec( ~로도 안되고

PlatformUI.getWorkbench().getDisplay().asyncExec(  ~로도 안된다.

 

Display.getDefault().asyncExec(new Runnable() {
@Override
  public void run() {
      여기에 작성

  }
  });

}

 

http://rusya7.blogspot.kr/2011/11/orgeclipseswtswtexception-invalid.html에서 해결법 찾음

 

 

페이지 제목이 Java-studying / swt-widget-thread-problem 인것을 보면 Thread 관련 소스예제들이 존재하는 듯하다.

https://github.com/rusya7/Java-studying/tree/master/swt-widget-thread-problem

 

 


 

 

There's only one UI thread in Eclipse. In a nutshell, the rules are:

  • If you got called as part of a UI operation (e.g. event handler, view initialization) you are in the UI thread.
  • All other operations that invoke a UI (e.g. a job which needs to show a dialog or send information to a view which modifies a widget) - need to sync with the UI thread.

This is basically done like this:

 Display.getDefault().syncExec( new Runnable() {  public void run() { } });

Your code goes in the run method. You may also use the asyncExec method to continue without waiting for the UI to finish.

Try using the snippet above to wrap the problematic code.

 

 -> http://www.vogella.com/articles/EclipseJobs/article.html


 

왜 이렇게 해결이 되는것인가???

 

Display javadoc ->

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FDisplay.html

 

  • Class Display  (Display 는 class, 디스플레이는 말그대로 영어 표현)

 

SWT와 기본 운영 체제 사이의 연결을 관리 할 책임이 있다.

가장 중요한 기능은 플랫폼 이벤트 모델의 관점에서 SWT 이벤트 루프를 구현하는 것이다. 또한 운영 체제에 대한 정보를 액세스하기위한 다양한 방법을 제공하고, 어떤 SWT를 할당 운영 체제 리소스를 전체 제어 할 수 있다.

 

SWT로 만드는 응용 프로그램은 기존의 Display가 dispose() 메시지를 보내지 않은이상, 거의.. 단 하나의 Display만 존재한다.

 

SWT에서 Display instance를 생성 한 스레드가 해당 디스플레이의 사용자 인터페이스 스레드로 구분된다. (메인 스레드와 사용자 스레드는 같다는 말같다. 대신 아래나오지만, )

 

특정 디스플레이에 대한 사용자 인터페이스 스레드는 다음과 같은 특수 속성이 있다. :

1. The event loop for that display must be run from the thread.


2. Some SWT API methods (notably, most of the public methods in Widget and its subclasses), may only be called from the thread. (To support multi-threaded user-interface applications, class Display provides inter-thread communication methods which allow threads other than the user-interface thread to request that it perform operations on their behalf.)


3. The thread is not allowed to construct other Displays until that display has been disposed. (Note that, this is in addition to the restriction mentioned above concerning platform support for multiple displays. Thus, the only way to have multiple simultaneously active displays, even on platforms which support it, is to have multiple threads.)

 

1. 디스플레이에 대한 event loop는 스레드에서 실행해야만 한다.

2. 일부 SWT api methods(특히, 위젯의 public method의 대부분)는 쓰레드로 불려야만 한다. (multi-threaded user-interface 응용 프로그램을 지원하기 위해, class Display는

inter-thread communication methods를 제공한다(자신의 작업을 대신수행하는 user-interface thread 보다는 말이다)

3. 스레드는 디스플레이가 dispose되기전까지 다른 Display를 허락하지 않는다. 심지어 multiple displays를 지원하는 플랫폼에서조차. 그래서 mutiple displays를 활성화 하는 방법은 multiple thread 뿐이다.

 

 

  • Display.getDefault

Returns the default display. One is created (making the thread that invokes this method its user-interface thread) if it did not already exist.

 

  • Display.getDefault.asyncExec

Causes the run() method of the runnable to be invoked by the user-interface thread at the next reasonable opportunity. The caller of this method continues to run in parallel, and is not notified when the runnable has completed. Specifying null as the runnable simply wakes the user-interface thread when run.

Note that at the time the runnable is invoked, widgets that have the receiver as their display may have been disposed. Therefore, it is necessary to check for this case inside the runnable before accessing the widget.

 

 

 


[참고]

Eclipse Jobs and Background Processing

http://www.vogella.com/articles/EclipseJobs/article.html

 

Display javadoc

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FDisplay.html

 

 

 

posted by cozyboy
: