On 06/08/2011 01:30 AM, Reinier Zwitserloot wrote:
That's quite a good idea, though, how would you configure the code that checks that we're in the appropriate thread? As far as I can tell this requires unique code for all GUI frameworks (which fortunately mostly means just 2: Swing, and SWT, and SWT mostly does its own checks already).

Three: actually I'm using it with Android - even though I must confess I've not yet understood how to test the UI threading on Android. In any case, I agree on the importance on static analysis. The first reason for which I started using those annotations is documentation.

PS Of course, one could also generate the proper code. For instance, I've set a rule that all the methods in my views must be callable by any thread - in other words, it's up to the views to take care of threading (this makes sense since I'm designing the core of the application which is independent of Android - it could be implemented in Android, Swing, a web framework, etc. Thus threading issues must be addressed in technology-dependent classes. For instance, all my methods in Android views are such as:

public void doSomething()
  {
     post(new Runnable()
       {
          public void run()
             {
                ...
             }
       });
  }


Now, Lombok could detect that the class extends android.view.View and:

+ for methods marked with @ThreadConfined(UI) it adds an assertion
+ for methods marked with @ThreadConfined(ANY) it automatically wraps the code as above (even better: it wraps if needed, dynamically)
+ for methods marked with @ThreadConfined(NOT_UI) it alwyas wraps the code

etc...

Of course, this could be done for classes extending java.awt.Component, only invoking the EventQueue.invokeLater() instead of post().


Event--
Fabrizio Giudici - Java Architect, Project Manager
Tidalwave s.a.s. - "We make Java work. Everywhere."
java.net/blog/fabriziogiudici - www.tidalwave.it/people
[email protected]

--
You received this message because you are subscribed to the Google Groups "The Java 
Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to