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 ?
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).
Related
I have a Weblogic 10.3 server and an ear application deployed on it.
I want that one of the servlets (that this application uses) always will have free threads to perform requests. Can I set for this servlet a separate thread pool? Or can you advise me something else?
Thank you,
Alex
Figured it out by myself.
I needed to define a workmanager in weblogic.xml of my application and in web.xml I needed to apply the new workmanager to my servlet.
More about creating and using workmanagers in WebLogic:
http://docs.oracle.com/cd/E23943_01/web.1111/e13701/self_tuned.htm#CNFGD117
http://www.itbuzzpress.com/weblogic-tutorials/weblogic-pools-configuration/using-workmanagers-in-your-applications.html
Hazel cast creates a number of threads. If my application is deployed in a j2ee environment, creating threads is discouraged. Is there a way to enable hazelcast to use application server managed threads?
There is no way to do that and there are no plans to make that happen.
Why do you think that app servers don't like you creating threads? I have done on quite a few and never had problems.
I'm trying to execute subprocesses from within my application server (Glassfish 3.1.2)
Therefore I discovered the Apache Commons Exec library. The problem is that this library creates threads which should not be done on an application server because the server is not aware of these threads.
What could be a solution to this problem?
Would it be possible to create a message component written in Java SE who consumes messages containing information about pending jobs and register it with the application server?
The application server would then not have to deal with runtime exceptions and threads but just consume messages which contain the result or an exception.
Do you have any better ideas?
You could either use:
MDB (as pointed by duffymo),
Servlets 3.0 asynchronous processing,
Asynchronous EJB invocation.
Effectively, it should give you similar functionality as plain subprocesses.
Using Java SE component which communicates with Java EE just to overcome using threads on your own sounds a bit like an overkill. Just read about mentioned solutions and try if any of them fits your needs.
Message driven beans were designed for asynchronous processing. It could be a solution to your problem. You can create a separate listener thread pool sized to handle the traffic.
I have a traditional 3-tier application with spring. One of my repositories needs > 3 minutes for initialization so I thought about some multi-threaded approach in order to speed up the whole process - I think most service and controllers in my dependency tree can already be started so only a few must wait for the last repository to come up.
Is there any best practice approach?
Use Spring's Executor abstraction. And if you are within a app server then I suggest you use application server's work-manager (spring supports it). For e.g. WebSphere app server and Weblogic both support registering the workmanagers in JNDI. You can then pass the jndi name to spring. Task Executors
are there any performance limitations using IBM's asynchbeans?
my apps jvm core dumps are showing numerous occurences of orphaned threads. Im currently using native jdk unmanaged threads. Is it worth changing over to managed threads?
In my perspective asynchbeans are a workaround to create threads inside Websphere J2EE server. So far so good, websphere lets you create pool of "worker" threads, controlling this way the maximum number of threads, typical J2EE scalability concern.
I had some problems using asynchbeans inside websphere on "unmanaged" threads (hacked callbacks from JMS Listener via the "outlawed" setMessageListener). I was "asking for it" not using MDBs in the first place, but I have requisites that do not feet MDB way.