Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6977939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:41:28+00:00 2026-05-27T17:41:28+00:00

I am trying to work out how to develop a reasonably scalable batch-processing framework

  • 0

I am trying to work out how to develop a reasonably scalable batch-processing framework for a webapp I am writing.

I am using Spring MVC for the webapp, with a custom DAO layer (to access the database a UnitOfWork instance is needed to be constructed from a UnitOfWorkFactory that is set as @Autowired and injected at runtime by Spring).

I am using the Spring Scheduler annotations (@Scheduled) to schedule tasks, however I want these tasks to run on different machines in my cluster. Each batch job should be picked up by one of the cluster machines and then executed.

Hazelcast seemed like a natural fit for this as the Distributed Execution design appeared really simple and elegant for this purpose.

I am running into a problem that doesn’t seem to be covered by the documentation. I have read the documentation about Spring Integration however this seems focused at how to configure Hazelcast using Spring (which I have done already).

When the scheduler indicates that the task is to start I want to create a new instance of the task (a Callable instance) and submit it to the DistributedExecutor. When a cluster machine receives the task to run I need the Spring container on the cluster machine to inject the UnitOfWorkFactory instance into the batch task before the task attempts to execute it. Each of the clusters starts with Spring and will have the UnitOfWorkFactory already instantiated with the correct details, the problem is with getting the UnitOfWorkFactory instance injected into my task.

Does anybody know how I can configure my application so that Hazelcast can have the UnitOfWorkFactory injected automatically when a Callable is started? I have tried marking the Callable as Serializable and ApplicationContextAware but I still get NullPointerException when trying to run the task.

I could access the ApplicationContext directly, however I would rather not as it will restrict the testability of my tasks and introduce a hard-dependency on Spring for my batch jobs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:41:29+00:00Added an answer on May 27, 2026 at 5:41 pm

    By version 2.1 Hazelcast can inject Spring context and/or Spring beans into Hazelcast managed objects.

    If you configure Hazelcast using Hazelcast Spring configuration and annotate a bean using @SpringAware, Hazelcast will ask Spring to inject dependencies of that bean.

    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:hz="http://www.hazelcast.com/schema/spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.hazelcast.com/schema/spring
                http://www.hazelcast.com/schema/spring/hazelcast-spring-2.1.xsd">
       <hz:hazelcast id="instance">
          <hz:config>
             <hz:group name="dev" password="password"/>
             <hz:network port="5701" port-auto-increment="false">
                <hz:join>
                    <hz:multicast enabled="false" />
                    <hz:tcp-ip enabled="true">
                        <hz:members>10.10.1.2, 10.10.1.3</hz:members>
                    </hz:tcp-ip>
                </hz:join>
             </hz:network>
             ...
          </hz:config>
       </hz:hazelcast>
    
       <bean id="someBean" class="com.hazelcast.examples.spring.SomeBean" 
              scope="singleton" />
       ...
    </beans>
    

    @SpringAware 
    public class SomeTask implements Callable<Long>, ApplicationContextAware, Serializable {
       private transient ApplicationContext context;
       private transient SomeBean someBean;
    
       public Long call() throws Exception {
         return someBean.value;
       }
    
       public void setApplicationContext(final ApplicationContext applicationContext)
           throws BeansException {
          context = applicationContext;
       }
    
       @Autowired
       public void setSomeBean(final SomeBean someBean) {
          this.someBean = someBean;
       }
    }
    

    For older versions than 2.1:

    Versions before 2.1 of Hazelcast are not Spring aware, so it is not possible to inject Spring context or any Spring bean into a Hazelcast managed object for pre-2.1 versions.

    There is a post asking about this feature on Hazelcast group.

    Hazelcast / Dependency injection for Callable

    As you may already know and suggested in Hazelcast group you can access Spring ApplicationContext using;

    public class ApplicationContextProvider implements ApplicationContextAware {
        private static ApplicationContext context = null;
    
        public synchronized void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
            if(context == null) {
                context = applicationContext;
            }
        }
    
        public static <T> T getBean(String name) {
            return (T) context.getBean(name);
        }
    }  
    
    class MyCallable implements Callable {
        ....
        public Object call() throws Exception {
            SomeServiceBean bean = ApplicationContextProvider.getBean("serviceBean");
            ....
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying work out with MERGE statment to Insert / Update Dimension Table
I am trying to work out the best database model for the current setup:
I am trying to work out how to get the value of table cell
I'm trying to work out a way of passing the web current http context
I am trying to work out a code sample to demonstrate the debugging functionality
I am trying to work out the format of a password file which is
I'm trying to work out what a BizTalk call to a web service is
I'm trying to work out what the best method to passing a large number
I'm trying to work out how to iterate though a returned SimpleXML object. I'm
i'm trying to work out the best method to perform logging in the application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.