How can an EJB parallelize a long, CPU intensive process?

前端 未结 6 753
礼貌的吻别
礼貌的吻别 2020-12-05 11:51

The application has a CPU intensive long process that currently runs on one server (an EJB method) serially when the client requests it.

It’s theoretically possible

6条回答
  •  北海茫月
    2020-12-05 12:42

    I once participated in a project where EJB transactions ran for up to 5 hours at a time. Aargh!

    This same application also had a BEA specialist consultant who approved that they started additional threads from the transactions. While it's disrecommended in the specs and elsewhere, it doesn't automatically result in failure. You need to be aware that your extra threads are outside the container's control and thus if something goes wrong it's your fault. But if you can assure that the number of threads started in the worst case doesn't exceed reasonable limits, and that they all terminate cleanly within reasonable time, then it is quite possible to work like this. In fact, in your case it sounds like the almost-only solution.

    There are some slightly esoteric solutions possible where your EJB app reaches out to another app for a service, which then does the multithreading in itself before returning to the EJB caller. But this is essentially just shifting the problem around.

    You may, however, consider a thread pooling solution to keep an upper limit on the number of threads spawned. If you have too many threads your application will behave horribly.

提交回复
热议问题