Starting with Griffon 0.9.2 there's also the possibility to define an specific thread execution policy for methods and properties via annotations
This feature is only available for Groovy code at the moment as it relies on the AST Transformation framework.
You must annotate a method or property with @griffon.transform.Threading
and define a value of type griffon.transform.Threading.Policy
(though the annotation uses Threading.Policy.OUTSIDE_UITHREAD
by default). Annotated methods and properties must conform to these rules
- must be public.
- name does not match an event handler.
- must pass
GriffonClassUtils.isPlainMethod()
if it's a method.
- must have
void
as return type if it's a method.
- its value must be a closure (including curried method pointers) if it's a property.
Here's a trivial examplepackage sampleimport griffon.transform.Threadingclass Sample {
@Threading
void doStuff() {
// executed outside of the UI thread
} @Threading(Threading.Policy.INSIDE_UITHREAD_SYNC)
void moreStuff() {
// executed synchronously inside the UI thread
} @Threading
def work = {
// executed outside of the UI thread
} @Threading(Threading.Policy.INSIDE_UITHREAD_SYNC)
def update = {
// executed synchronously inside the UI thread
}
}
It is worth noting that a @Threading
annotation applied to a Controller's action/method will take precedence, this means you can force an specific threading policy on a Controller action other than the default one.package sampleclass SampleController {
@Threading(Threading.Policy.INSIDE_UITHREAD_ASYNC)
def popupDialog = {
// build and show the dialog
} def equivalentPopupDialog = {
execInsideUIAsync {
// build and show the dialog
}
}
}