How to use the IBM WebSphere work manager together with the Spring #Scheduled annotation in my servlet?
Spring provides the WorkManagerTaskExecutor. It allows to configure a work manager as described in the WebSphere docs or in this SO answer. However I don't see a relation to the #Scheduled annotation and can't find any documentation how it works internally.
My goal is to configure scheduled tasks in a convenient way (as given by #Scheduled) but I need the task threads created by the scheduler to be managed by WebSphere.
EDIT: In the original question I confused DefaultManagedTaskExecutor with WorkManagerTaskExecutor as the latter is deprecated in favor of the first. Now I understand that WorkManagerTaskExecutor is Java EE 6 (and therefore required for our WebSphere 8.5 environment) whereas DefaultManagedTaskExecutor belongs to Java EE 7 and can indeed be configured for #Scheduled which is documented with the #EnableScheduling annotation.
I can see what you mean that Spring documentation appears vague as to the relation between task executors that you configure and #Scheduled. Absent that sort of guarantee, you could verify observationally if scheduled tasks are running on WebSphere Application Server threads by printing the stack from one of your methods and confirming the presence of com.ibm.ws.* packages. One easy way to do that is,
new Exception("capturing the stack").printStackTrace(System.out);
Spring's DefaultManagedTaskExecutor is documented to rely on java:comp/DefaultManagedExecutorService, which requires Java EE 8 (or Jakarta EE) and ought to work with version 9 of WebSphere Application Server traditional. It should also work with WebSphere Application Server Liberty.
If you are on 8.5.5 or earlier, you would need the WorkManagerTaskExecutor (referenced in one of the docs that you linked) which is based on the CommonJ WorkManager.
Related
The end goal is to have a Spring Boot app that works with an XA transaction coordinator, in particular that coordinator would be Narayana.
We think that since Wildfly uses IronJacamar, Spring Boot could use it too.
Where can we find examples of this, or some instruction to get us there quickly?
The IronJacamar is used as the JCA and pooling library for WildFly but for other projects the Narayana can be configured to used other libraries. IronJacamar is fully fledged implementation of the Java EE JCA specifiation which is often not necessary when running on runtimes like Quarkus or Spring.
For example within Quarkus (https://quarkus.io/) there is used Agroal (https://github.com/agroal/agroal), for Apache Tomcat it could be DBCP2 (https://github.com/web-servers/narayana-tomcat).
For Narayana and Spring integration it could be recommended to work with the Snowdrop extension - https://github.com/snowdrop/narayana-spring-boot - where DBCP2 (instead of IronJacamar) is used.
I am working on a Server Migration Project from Weblogic to Websphere. The problem is that in Weblogic, we are already using a class specified as Startup-class in Weblogic (and arguments to the class like log4j config file) which is present in a jar which is added to Weblogic classpath by editing the startup script. This jar initializes a global log4j file which is for all the apps deployed on the server and not for any particular app. Each app is distinguished by a category of log4j.
Now I could not find a similar thing in Websphere. So what is the best solution? I can create a new application which would do all initializations like that of the startup classes. I thought of using startup-beans but read in some IBM documentation that they are deprecated due to EJB 3.1 Session Beans. Also how to make sure this app loads first? By giving Websphere xml file startup weight 1 like here?
I am using Weblogic 6.3.2 and Websphere 8.5
The WebSphere migration toolkit suggests to replace the WebLogic T3StartupDef and T3ShutdownDef implementations with either a ServletContextListener implementation, session startup bean (Singleton), or a servlet that is configured to load at startup time. If you haven't used the WebLogic to WebSphere migration toolkit, check it out. It provides a lot of help especially with deployment descriptor extensions.
The #Singleton session bean in EJB 3.1 replaces the proprietary WebSphere startup bean.
The best approach depends on the type of module you need the startup logic.
If you are considering the custom services option, note that the com.ibm.websphere.runtime package is not available in Liberty if you are considering the Liberty server.
It sounds like custom services (or a custom feature on Liberty profile) are the best analog if you need to run logic during server startup. Otherwise, if you just need to add a library to every application, then create a shared library and then either associate it with the server or associate it with specific applications or modules.
I have an Spring based J2EE application which runs well on Weblogic, I wanted to move it to Tomcat.
It seems tomcat doesn't support JTA Transaction Manager without external jar help like Atomikos, JOTM, Bitronix, SimpleJTA.
I am reluctant to make changes into my application where i am already using annotation based JTA transaction manager.
Are there alternatives for JTA Transaction Manager which I can use so that I am able to switch from weblogic to tomcat or tomcat to weblogic or any other server without changing my configuration file each time?
All in all what's best for transaction manager configuration when you want to keep your application (war) independent of server(s).
You could try TomEE.
It's a Java EE 6 server that meets the Web Profile requirements and is based on Tomcat.
So it will support JTA transactions.
You can get it from http://tomitribe.com
Just to give you a more direct link to TomEE: http://tomee.apache.org/download/tomee-1.7.2.html
If your application is configured and developed to use Weblogic then chances are you are using JDNDI to lookup the JTA transaction manager and your datasources.
So any solution that supports the same lookups would work.
For Atomikos, we recently added (commercial) support for Tomcat's JNDI space - check out http://www.atomikos.com/Main/BuyOnline to learn more.
Hope this helps!
We have an issue, that if you start JBoss 6 with our Java EE 6 applications deployed, where one of them uses a JMS Queue, the related MDB won't consume any messages until you re-deploy the applications. The MDB is using a Singleton with a Startup annotation.
My research so far resulted in the assumption that this is caused by HornetQ being deployed after the application.
I also found some hints to get around this here and here, but I neither was able (and by the way didn't like) to use JBoss specific annotation in my applications due to missing Maven dependency nor am I using any deployment descriptor file so far.
So my question is, how do I ensure, preferrably with standard Java EE annotations or HornetQ/JBossAS configuration file that the queues are deployed before my application gets deployed?
I am thinking about a platform for study application (it is team work). I mean standard Java EE 5 (or maybe try raw Java EE 6) and Spring. What is your choose? (I don't mean Spring MVC but Spring Beans and EJB 3.0)
Also I would like to know what app server you use? (now I use GlassFish v2)
I would recommend Spring without EJBs.
My favorite choice of Java EE app server is WebLogic, but I don't know if Oracle is as generous as BEA was about making it available to developers.
I'd recommend using Tomcat as your app server. If you need JMS, add ActiveMQ.
As duffymo says, look at Spring without EJBs. Spring is very powerful, regardless of how much/little you use. I don't know of anyone using EJBs now. Having said that, EJBs have changed dramatically over the years, and now resemble ORMs such as Hibernate (which is worth checking out in itself).
For app servers, check out JBoss. It's free/open-source, and you can choose the web component between Tomcat and Jetty. It's JMX backbone allows you to easily monitor its state and to integrate your own JMX beans into that backbone (if you're using Spring, you can JMX-enable any bean with a simple configuration).
If you want Java EE 6 then the choice appears to be either Glassfish 3 or the beta of JBoss 6. As some of the others have said, I also prefer Spring to Java EE's EJBs.
I don't see much point in looking at Java EE 5, unless you think you will be working with it in the future (possible as some companies are conservative in using newer versions of technology).