0

i have a webapp written with spring 3 and struts 2 that is hosted on a glassfish server. In this app i have two webservices that need to do some background work without delaying the accessed method response.

So, now i use a spring bean that uses an instance of org.springframework.core.task.TaskExecutor and from there i run my new thread.

Is this the correct/best practice approach in context of using this app on glassfish? or should find another method of doing this ?

skaffman
  • 381,978
  • 94
  • 789
  • 754
Videanu Adrian
  • 922
  • 3
  • 16
  • 35

1 Answers1

0

It's discouraged to create your own threads because the app server is meant to be in charge. See the answers to Why is spawning threads in Java EE container discouraged?

However in practice, especially if it's the only application on there, you might be OK, especially if you use a fixed thread pool. Be sure all the threads are gone when you undeploy the app. (I expect Spring classes will handle disposal on undeploy / shutdown correctly, if you declare them within the Spring container).

Community
  • 1
  • 1
artbristol
  • 30,694
  • 5
  • 61
  • 93
  • yes, this is my only app running on that server. Thanks for link. – Videanu Adrian Jan 05 '12 at 14:04
  • Note that there is now a sanctioned way to create threads in web containers: http://stackoverflow.com/questions/3212255/java-ee-specification-and-multi-threading/19404307#19404307 – Erhannis Feb 02 '17 at 15:01