Groovy/grails: pass parameter to thread
grails, groovy, multithreading
Solution
The problem isn't so much that "the thread is started after the controller has been left by the user" but rather that `springSecurityService.currentUser` is thread-local state that gives you different values when called from different threads. But if you save this thread's value of `springSecurityService.currentUser` in a local variable you should be able to access that inside the closure:
if(springSecurityService.currentUser){
def theUser = springSecurityService.currentUser
task {
// do something with theUser
}.get()
}
Problem
In a grails controller a new thread (task / Promise) is started. But the user is null when i try to get it within the thread. ``` if(springSecurityService.currentUser){ task { // do something with the current user // springSecurityService.currentUser is null here!!!!!! }.get() } ``` How can i pass the user as a parameter to the task?