[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New Swing Library (JFC)

The new Java Foundation Classes (codename Swing) strongly discourage the use of multi-threaded GUI programming. Quoting from one source (http://java.sun.com:80/products/jfc/swingdoc-archive/threads.html)

                          It is our basic belief that extreme caution is warranted when
                          designing and building multi-threaded applications,
                          particularly those which have a GUI component. Use of
                          threads can be very deceptive. In many cases they appear to
                          greatly simplify programming by allowing design in terms of
                          simple autonomous entities focused on a single task. In fact in
                          some cases they do simplify design and coding. However, in
                          almost all cases they also make debugging, testing, and
                          maintenance vastly more difficult and sometimes impossible.
                          Neither the training, experience, or actual practices of most
                          programmers, nor the tools we have to help us, are designed
                          to cope with the non-determinism. For example, thorough
                          testing (which is always difficult) becomes nearly impossible
                          when bugs are timing dependent. This is particularly true in
                          Java where one program can run on many different types of
                          machines and OS platforms, and where each program must
                          work under both preemptive or non-preemptive scheduling.

                          As a result of these inherent difficulties, we urge you to think
                          twice about using threads in cases where they are not
                          absolutely necessary. However, in some cases threads are
                          necessary (or are imposed by other software packages) and
                          so subArctic provides a thread-safe access mechanism. This
                          section describes this mechanism and how to use it to safely
                          manipulate the interactor tree from an independent thread.

It is interesting to consider this strategy in the light of experience gained from occam. Whilst occam totally lacks the carefully designed library support of the JFC and the JDK, it does in principle allow straightforward multi-threaded GUI programming. Coping with non-determinism is a normal part of the occam design process, not the insurmountable issue faced by users of the JFC.

Perhaps a sensible approach is to use JavaPP channels to dissociate Swing GUIs from the underlying core application.
Richard Beton B.Sc. C.Phys. M.Inst.P.
Roke Manor Research Limited
--------- Standard Disclaimer about my own views etc etc --------
---------  My mail client accepts rich text (HTML) mail  --------
Welsh Highland Railway: http://www.whr.co.uk/WHR/WHR.html
Java: In a world without Fences, who needs Gates?