cancel
Showing results for 
Search instead for 
Did you mean: 

how to launch asynchronous/background task

former_member190457
Contributor
0 Kudos

Hi all,

I'd like to launch a background/asynchronous task performing some logic.

I know that JEE6 includes the @asynchronous annotation for EJB 3.1 methods, but it's not supported in the EJB 3.1 Lite spec implemented.

In addition, the usage of JMS is not possible since HANA Cloud does not implement it.

How can I launch an asynchronous task?

Thanks and regards

Vincenzo

View Entire Topic
Vlado
Advisor
Advisor
0 Kudos

Hi Vincenzo,

You are correct - asynchronous features (timers, MDBs) are not part of EJB Lite, and JMS is not part of Java EE 6 Web Profile (btw, it's Java EE, not JEE).

But... there is good news - you can use EJB timers with the SDK 2.x (though not officially supported). Check this blog for the details:

HTH!

--Vlado

former_member190457
Contributor
0 Kudos

Hi Jan and Vlado,

thanks so much for your valuable ideas.

I understand the timer service is not official supported, though I appreciate it might most certainly work ok. Spring would certainly be a good choice, though adding an additional degree of complexity as it is a different framework.

I found out also that the Quartz API can provide good support in the matter of job scheduling.

A good blog is found here:  http://scn.sap.com/people/aleksandar.zlatkovski/blog/2013/02/22/scheduling-jobs-on-sap-netweaver-clo...

Do you have any experience on this library or any opinion on whether it might be better/worse than the proposed options?

Thanks so much for your kind attention

Regards

0 Kudos

Hi Vincenzo,

I'm using Quarz in a productive application on SAP HANA Cloud Platform by just following the exact blog post that you have referred to. It works perfectly for my use case to schedule a regular job to send some notification mails.

I haven't tried EJB timers though.

Best regards,

Vesselin

Vlado
Advisor
Advisor
0 Kudos

Well, Quartz is also a framework on itself, and it's specifically designed for job scheduling scenarios. I don't have that much experience with it as with EJB timers, basically it requires at least some integration efforts but also can support more complex scenarios. On the other hand, EJB timers work out of the box and are a good fit for most use cases.

So, if you don't need some very special features that are not available with the EJB timer service, I would recommend to go for EJB timers and see how it works for you. If you need more, you can always switch to Quartz

HTH!

--Vlado

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

If you were planning to use spring for background tasks, you're in luck, because it also has it's own scheduler. The good news is that spring also supports Quartz as a plugin.

Quartz is a very nice lib/framework for scheduling jobs. I have used it quite often and never failed on me.

former_member190457
Contributor
0 Kudos

Hi Vlado,

thanks, that makes sense. I have a couple more questions on how to use the EJB timer for emulating a Thread. For instance:

  • how do you launch a timer to run immediately? Looking at the API, it should be something like "start in 1 second"?
  • how would you pass a parameter to the Timer instance before launching it? I guess one should specify a TimerConfig object from which the EJB could retrieve the necessary parameters, right?

Thanks so much, regards

Vincenzo

Vlado
Advisor
Advisor
0 Kudos

Sorry Vincenzo, I somehow missed your response.

Sure, you can use the TimerService.createTimer(long duration, java.io.Serializable info) method and pass 0 as duration. The info object can be any Serializable object, which you can then get from the Timer passed to the EJB @Timeout method.

HTH!

--Vlado

former_member190457
Contributor
0 Kudos

Hi Vlado,

after a bit of time, I'm following up on this topic in my project.

I have created a Stateless EJB with a Timeout annotated method.

When I deploy it within the lib folder of a WAR archive to the local HCP I get errors like:

Exception: class java.lang.NoClassDefFoundError: org/quartz/simpl/RAMJobStore: org/quartz/simpl/RAMJobStore

And I am not using Quartz, just the plain EJB @Timeout.

Is there anything I'm missing?

Thanks a lot

Regards

Vincenzo

Vlado
Advisor
Advisor
0 Kudos

Hi Vincenzo,

Yes, I reproduce it. This looks like an issue with the OpenEJB bundle - it uses some classes from Quartz but the corresponding packages are not imported in the Manifest. Let me try and clarify this with the colleagues responsible for the runtime container.

Cheers,

--Vlado

former_member190457
Contributor
0 Kudos

Thanks a lot Vlado for your support,

I'm eager to have the Timeout service fully working!

Regards

Vincenzo