SpringAsyncの注釈付きサービスメソッドでGrailsドメインオブジェクトを永続化する際に問題が発生しました。
簡略化されたコードは次のとおりです。
class DocumentService {
@Async
def process(Long documentId, Organization organization) {
...
def organizationCari = new OrganizationCari(organization: organization, active: true)
organizationCari.save(flush: true, failOnError: true)
print "Document processing..."
...
print "Document processed..."
}
}
メソッドを非同期で実行していますが、保存操作でスレッドが終了するため、コンソールに何も出力されないようです。エラーは発生しませんが、ドメインオブジェクトはまだ保持されていません。
非同期アノテーションを削除すると問題は解決しますが、メソッドを非同期で実行する必要があります。
Spring3.1.2でGrails2.1.1を使用しています。