I need a custom threda on my weblogic server; I cannot use TimerEJB or Delayed MDB since I have to use a 3d library.
I know that custom threads on application server are discouraged; here a related post (4 years old): Why is spawning threads in Java EE container discouraged?
Is it still discouraged? Can I use ExecutorService
or Quartz? Or I have to consider only commonj and worker manager?
On Weblogic 11g (EJB3.0) is dicouraged to create "own thread executor" (see also Java EE specification and multi threading) you should use:
example:
**If you cannot use Deleyed MDB or TimerService you need to work with Work Manager **.
Weblogic and Websphere are CommonJ (JSR 237 Timer & WorkManager) compliant; in other words they use a common interface to work with work manager; in weblogic, work managers regulate the life cycle of threads (Servlet, EJB, MDB,..., custom thread).
IMHO do not use
ExecutorService
since is not under the control of weblogic: if you stop the application (not the server) the threads under weblogic control will stop, the other threads should not terminate; I experienced this problem.Work Manager
The WorkManager feature in WebLogic Server is dynamic in nature, based on the number of incoming requests the thread pool size automatically re-sizes to maximize the throughput. To work with WorkManager you can access through commonj interface or MBean.
example:
Spring
For instance spring has an easy way to attach its own TaskExecutor to comonj worker manager:
Quartz
Quartz works on application servers and with spring they can use work manager
JAVA EE 7
JEE7 introduces Batch (JSR 352). The Batch Applications for the Java Platform API (Batch) provides a programming model for batch applications and a runtime for scheduling and executing jobs.
Executor Service
From java specifications:
In JEE7 Executor Service has been extended with
ManagedExecutorService
andManagedThreadFactory
.example:
Concluding: Weblogic
See http://www.oracle.com/technetwork/java/restrictions-142267.html