Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Asynchronous method in groovy

 
Ketan Parekh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using grails 1.3.4. We have a scenario where a user uploads a file on the web page and hits the submit button. The controller calls the grails service class and calls a method xyz(). The xyz() method is required to be asynchronous. We want the control to return back and while the xyz() method does some processing. The service class method has been annotated with @Async but we see the flow synchronised.

It seems like the grails service class is not recognizing the spring annotation.

Am I missing something or anyone has other ideas on how to make the method perform async ?

Thanks,
+Ketan Parekh
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because Grails uses spring under the hood doesn't really mean all of spring is supported, at least not without some more configuration. You would be better off using this plugin.
 
Ketan Parekh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Intially we were trying to use the spring @Async with grails but we were not successful it seemed like grails was not able recognise it. I looked at that plugin mentioned in the Grails Doc and were able to do it. Thanks Greg Appreciate for your help.

Now we are writing the unit test but some how the instance variable "def backgroundService" is not getting injected. Is there a way to mock it (since its plugin we were not able to mock it) or to inject it so I can unit test my method ?

+Ketan B. Parekh
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a unit test, you'd have to mock it. Unfortunately, I don't know how to tell you to do that. You might have better luck on the grails mailing list when it comes to plugin specific questions, as this seems to be. Most of the plugin authors monitor that list closely.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic