- 전체
- JAVA 일반
- JAVA 수학
- JAVA 그래픽
- JAVA 자료구조
- JAVA 인공지능
- JAVA 인터넷
- Java Framework
- Java GUI (AWT,SWING,SWT,JFACE)
- SWT and RCP (web RAP/RWT)[eclipse], EMF
SWT and RCP (web RAP/RWT)[eclipse], EMF SWT and multithreading
2015.11.07 22:41
SWT and multithreading
I must admit that I have always hated Swing and AWT. It took me several weeks to (fully?) understand all the events stuff. Regarding the GUI, I was a VB guy, and that means dragging and dropping visual components. In the early days it was slow, very slow. I remember running a Swing application remotely in a HPUX server using a X server like a bad nightmare. So I dropped rich clients in Java and embraced server side development with Servlets and JSPs. When I saw Eclipse and SWT for the first time, I thought ‘this guys have the killer rich client libraries for Java’. I threw away Netbeans and became an Eclipse believer. And SWT was like my ‘pending’ issue in my ‘favourites technologies to study’ list. Finally, I had the oportunity to use SWT in pure research project, just for fun. The learning curve for a Java guy with experience in Swing or AWT is almost non-existant…except for the multithreading. SWT is not thread safe. Swing guys can say now: ‘Ok, Swing is not thread safe either, but who cares’. If you want to use SWT in a multithreaded environment, you should care… Because SWT enforces good thread safe code. Otherwise you will get a ‘org.eclipse.swt.SWTException: Invalid thread access’. Basically, we have to make the SWT thread to manage all the User Interface events. The ‘Display’ class has a method called ‘asyncExec’ that enqueues a piece of code in the SWT thread events dispatcher. It works as follows: public void refresh() { This piece of code refresh the content of a table stored in an instance of HashMap. ‘shell_’ is the reference to the SWT Shell where the table is contained. The method ‘getTable’ returns a reference to the table itself. ‘table_’ is the HashMap that contains the values of the table. I have used a HashMap because I need to keep a reference to the row of the table easily. The core functionality is inside the ‘asyncExec’ method, which needs an object of the Runnable class. Then the ‘run’ method must implement the code that must be thread safe. SWT is single threaded, so it means that long running processes invoked from the events of the widgets can halt the execution of the application for a long period of time. The ‘asyncExec’ method can be used to execute long running processes. |
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.