Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Groovy and the fly likes Asynchronous method in groovy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Asynchronous method in groovy" Watch "Asynchronous method in groovy" New topic
Author

Asynchronous method in groovy

Ketan Parekh
Greenhorn

Joined: Sep 15, 2005
Posts: 20
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Ketan Parekh
Greenhorn

Joined: Sep 15, 2005
Posts: 20
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
wood burning stoves
 
subject: Asynchronous method in groovy
 
Similar Threads
Star UML questions for making UML diagrams for SCEA part 2 exam
which service() method is called
request.getParameter() returns null
calling sub class' method from super class
IceFaces - receive broadcast failed