CronJob Real time example


Requirement:

We need to run some task which should remove the products whose price is not defined and it is X days old in the system.

Now our business logic is to remove the products if its price is not defined and it is X no of days old.

Steps for the business logic


Load the Products which are X days old
Check if the product has price from the above product list
If the price is not defined , delete the product

Step 1


Since we need to add new configuration property called X days as dynamic value to the Cron Job, we need to define a new CronJob Item type

Define new Cron Job item type in items.xml as below
hybris\bin\custom\training\trainingcore\resources\trainingcore-items.xml

  1. <itemtype code="ProductsRemovalCronJob" extends="CronJob" jaloclass="de.hybris.platform.cronjob.jalo.ProductsRemovalCronJob"
  2.                   autocreate="true" generate="true">
  3.             <attributes>
  4.                 <attribute qualifier="xDaysOld" type="int">
  5.                     <modifiers read="true" write="true" optional="false"/>
  6.                     <defaultvalue>Integer.valueOf(10)</defaultvalue>
  7.                     <description>All Products older than this value in days and whose price is not defined will be removed
  8.                     </description>
  9.                     <persistence type="property"/>
  10.                 </attribute>
  11.             </attributes>
  12.         </itemtype>
<itemtype code="ProductsRemovalCronJob" extends="CronJob" jaloclass="de.hybris.platform.cronjob.jalo.ProductsRemovalCronJob"
                  autocreate="true" generate="true">
            <attributes>
                <attribute qualifier="xDaysOld" type="int">
                    <modifiers read="true" write="true" optional="false"/>
                    <defaultvalue>Integer.valueOf(10)</defaultvalue>
                    <description>All Products older than this value in days and whose price is not defined will be removed
                    </description>
                    <persistence type="property"/>
                </attribute>
            </attributes>
        </itemtype>

Defined a new Cron Job item type ProductsRemovalCronJob which extends CronJob item type
So all the attributes of CronJob item type are also inherited to this new Cron Job item type.

Do ant all and refresh the platform folder to check ProductsRemovalCronJobModel.java is generated

Step 2


Create a class which acts as a Job by extending AbstractJobPerformable class and override the perform() method to have our business logic

  1. Created the class inside our custom core extension as below
  2.  
  3. package org.training.core.jobs;
  4.  
  5. import de.hybris.platform.cronjob.enums.CronJobResult;
  6. import de.hybris.platform.cronjob.enums.CronJobStatus;
  7. import de.hybris.platform.cronjob.model.ProductsRemovalCronJobModel;
  8. import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
  9. import de.hybris.platform.servicelayer.cronjob.PerformResult;
  10.  
  11.  
  12. public class ProductsRemovalJob extends AbstractJobPerformable<ProductsRemovalCronJobModel>
  13. {
  14.     @Override
  15.     public PerformResult perform(final ProductsRemovalCronJobModel productsRemovalCronJobModel)
  16.     {
  17.  
  18.         return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
  19.     }
  20.  
  21. }
Created the class inside our custom core extension as below

package org.training.core.jobs;

import de.hybris.platform.cronjob.enums.CronJobResult;
import de.hybris.platform.cronjob.enums.CronJobStatus;
import de.hybris.platform.cronjob.model.ProductsRemovalCronJobModel;
import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
import de.hybris.platform.servicelayer.cronjob.PerformResult;


public class ProductsRemovalJob extends AbstractJobPerformable<ProductsRemovalCronJobModel>
{
	@Override
	public PerformResult perform(final ProductsRemovalCronJobModel productsRemovalCronJobModel)
	{

		return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
	}

}

This is a class which does not have any business logic written for the Job to perform.

Let’s define the Business logic for the same as below
hybris\hybris\bin\custom\training\trainingcore\src\org\training\core\jobs\ProductsRemovalJob.java

  1. package org.training.core.jobs;
  2.  
  3. import de.hybris.platform.core.model.product.ProductModel;
  4. import de.hybris.platform.cronjob.enums.CronJobResult;
  5. import de.hybris.platform.cronjob.enums.CronJobStatus;
  6. import de.hybris.platform.cronjob.model.ProductsRemovalCronJobModel;
  7. import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
  8. import de.hybris.platform.servicelayer.cronjob.PerformResult;
  9. import de.hybris.platform.servicelayer.exceptions.ModelRemovalException;
  10. import de.hybris.platform.servicelayer.model.ModelService;
  11. import de.hybris.platform.site.BaseSiteService;
  12. import de.hybris.platform.solrfacetsearch.config.FacetSearchConfig;
  13. import de.hybris.platform.solrfacetsearch.config.FacetSearchConfigService;
  14. import de.hybris.platform.solrfacetsearch.config.exceptions.FacetConfigServiceException;
  15. import de.hybris.platform.solrfacetsearch.indexer.IndexerService;
  16. import de.hybris.platform.solrfacetsearch.indexer.exceptions.IndexerException;
  17. import de.hybris.platform.solrfacetsearch.model.config.SolrFacetSearchConfigModel;
  18. import de.hybris.platform.tx.Transaction;
  19.  
  20. import java.util.ArrayList;
  21. import java.util.Calendar;
  22. import java.util.Date;
  23. import java.util.List;
  24.  
  25. import org.apache.log4j.Logger;
  26. import org.springframework.util.CollectionUtils;
  27. import org.training.core.dao.CustomProductsDAO;
  28.  
  29.  
  30. public class ProductsRemovalJob extends AbstractJobPerformable<ProductsRemovalCronJobModel>
  31. {
  32.     public static final String SITE_UID = "apparel-uk";
  33.     private CustomProductsDAO customProductsDao;
  34.     private ModelService modelService;
  35.     private IndexerService indexerService;
  36.     private FacetSearchConfigService facetSearchConfigService;
  37.     private BaseSiteService baseSiteService;
  38.  
  39.     private final static Logger LOG = Logger.getLogger(ProductsRemovalJob.class.getName());
  40.  
  41.     @Override
  42.     public PerformResult perform(final ProductsRemovalCronJobModel productsRemovalCronJobModel)
  43.     {
  44.         final int noOfDaysOldToRemove = productsRemovalCronJobModel.getXDaysOld();
  45.         final Calendar cal = Calendar.getInstance();
  46.         cal.add(Calendar.DAY_OF_MONTH, -noOfDaysOldToRemove);
  47.         final Date oldDate = cal.getTime();
  48.         final List<ProductModel> productModelListToBeDeleted = new ArrayList<>();
  49.         final List<ProductModel> productModelList = customProductsDao.findAllProductsOlderThanSpecifiedDays(oldDate);
  50.         LOG.debug("Products older than specified days size:" + productModelList.size());
  51.         for (final ProductModel productModel : productModelList)
  52.         {
  53.             if (CollectionUtils.isEmpty(productModel.getEurope1Prices()))
  54.             {
  55.                 productModelListToBeDeleted.add(productModel);
  56.             }
  57.         }
  58.  
  59.         if (!CollectionUtils.isEmpty(productModelListToBeDeleted))
  60.         {
  61.             Transaction tx = null;
  62.             try
  63.             {
  64.                 tx = Transaction.current();
  65.                 tx.begin();
  66.                 getModelService().removeAll(productModelListToBeDeleted);
  67.                 tx.commit();
  68.             }
  69.             catch (final ModelRemovalException e)
  70.             {
  71.                 if (null != tx)
  72.                 {
  73.                     tx.rollback();
  74.                 }
  75.                 LOG.error("Could not remove the product list -->" + e);
  76.             }
  77.         }
  78.  
  79.         try
  80.         {
  81.             final SolrFacetSearchConfigModel facetSearchConfigModel = baseSiteService.getBaseSiteForUID(SITE_UID)
  82.                     .getSolrFacetSearchConfiguration();
  83.             final FacetSearchConfig facetSearchConfig = facetSearchConfigService.getConfiguration(facetSearchConfigModel.getName());
  84.             indexerService.performFullIndex(facetSearchConfig);
  85.         }
  86.         catch (final FacetConfigServiceException | IndexerException e)
  87.         {
  88.             LOG.error("Could not index the products -->" + e);
  89.         }
  90.  
  91.         return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
  92.     }
  93.  
  94.     public CustomProductsDAO getCustomProductsDao()
  95.     {
  96.         return customProductsDao;
  97.     }
  98.  
  99.     public void setCustomProductsDao(final CustomProductsDAO customProductsDao)
  100.     {
  101.         this.customProductsDao = customProductsDao;
  102.     }
  103.  
  104.     public ModelService getModelService()
  105.     {
  106.         return modelService;
  107.     }
  108.  
  109.     @Override
  110.     public void setModelService(final ModelService modelService)
  111.     {
  112.  
  113.         this.modelService = modelService;
  114.     }
  115.  
  116.    
  117.     public IndexerService getIndexerService()
  118.     {
  119.         return indexerService;
  120.     }
  121.  
  122.    
  123.     public void setIndexerService(final IndexerService indexerService)
  124.     {
  125.         this.indexerService = indexerService;
  126.     }
  127.  
  128.    
  129.     public FacetSearchConfigService getFacetSearchConfigService()
  130.     {
  131.         return facetSearchConfigService;
  132.     }
  133.  
  134.    
  135.     public void setFacetSearchConfigService(final FacetSearchConfigService facetSearchConfigService)
  136.     {
  137.         this.facetSearchConfigService = facetSearchConfigService;
  138.     }
  139.  
  140.     public BaseSiteService getBaseSiteService()
  141.     {
  142.         return baseSiteService;
  143.     }
  144.  
  145.     public void setBaseSiteService(final BaseSiteService baseSiteService)
  146.     {
  147.         this.baseSiteService = baseSiteService;
  148.     }
  149.  
  150. }
package org.training.core.jobs;

import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.cronjob.enums.CronJobResult;
import de.hybris.platform.cronjob.enums.CronJobStatus;
import de.hybris.platform.cronjob.model.ProductsRemovalCronJobModel;
import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
import de.hybris.platform.servicelayer.cronjob.PerformResult;
import de.hybris.platform.servicelayer.exceptions.ModelRemovalException;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.site.BaseSiteService;
import de.hybris.platform.solrfacetsearch.config.FacetSearchConfig;
import de.hybris.platform.solrfacetsearch.config.FacetSearchConfigService;
import de.hybris.platform.solrfacetsearch.config.exceptions.FacetConfigServiceException;
import de.hybris.platform.solrfacetsearch.indexer.IndexerService;
import de.hybris.platform.solrfacetsearch.indexer.exceptions.IndexerException;
import de.hybris.platform.solrfacetsearch.model.config.SolrFacetSearchConfigModel;
import de.hybris.platform.tx.Transaction;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.util.CollectionUtils;
import org.training.core.dao.CustomProductsDAO;


public class ProductsRemovalJob extends AbstractJobPerformable<ProductsRemovalCronJobModel>
{
	public static final String SITE_UID = "apparel-uk";
	private CustomProductsDAO customProductsDao;
	private ModelService modelService;
	private IndexerService indexerService;
	private FacetSearchConfigService facetSearchConfigService;
	private BaseSiteService baseSiteService;

	private final static Logger LOG = Logger.getLogger(ProductsRemovalJob.class.getName());

	@Override
	public PerformResult perform(final ProductsRemovalCronJobModel productsRemovalCronJobModel)
	{
		final int noOfDaysOldToRemove = productsRemovalCronJobModel.getXDaysOld();
		final Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DAY_OF_MONTH, -noOfDaysOldToRemove);
		final Date oldDate = cal.getTime();
		final List<ProductModel> productModelListToBeDeleted = new ArrayList<>();
		final List<ProductModel> productModelList = customProductsDao.findAllProductsOlderThanSpecifiedDays(oldDate);
		LOG.debug("Products older than specified days size:" + productModelList.size());
		for (final ProductModel productModel : productModelList)
		{
			if (CollectionUtils.isEmpty(productModel.getEurope1Prices()))
			{
				productModelListToBeDeleted.add(productModel);
			}
		}

		if (!CollectionUtils.isEmpty(productModelListToBeDeleted))
		{
			Transaction tx = null;
			try
			{
				tx = Transaction.current();
				tx.begin();
				getModelService().removeAll(productModelListToBeDeleted);
				tx.commit();
			}
			catch (final ModelRemovalException e)
			{
				if (null != tx)
				{
					tx.rollback();
				}
				LOG.error("Could not remove the product list -->" + e);
			}
		}

		try
		{
			final SolrFacetSearchConfigModel facetSearchConfigModel = baseSiteService.getBaseSiteForUID(SITE_UID)
					.getSolrFacetSearchConfiguration();
			final FacetSearchConfig facetSearchConfig = facetSearchConfigService.getConfiguration(facetSearchConfigModel.getName());
			indexerService.performFullIndex(facetSearchConfig);
		}
		catch (final FacetConfigServiceException | IndexerException e)
		{
			LOG.error("Could not index the products -->" + e);
		}

		return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
	}

	public CustomProductsDAO getCustomProductsDao()
	{
		return customProductsDao;
	}

	public void setCustomProductsDao(final CustomProductsDAO customProductsDao)
	{
		this.customProductsDao = customProductsDao;
	}

	public ModelService getModelService()
	{
		return modelService;
	}

	@Override
	public void setModelService(final ModelService modelService)
	{

		this.modelService = modelService;
	}

	
	public IndexerService getIndexerService()
	{
		return indexerService;
	}

	
	public void setIndexerService(final IndexerService indexerService)
	{
		this.indexerService = indexerService;
	}

	
	public FacetSearchConfigService getFacetSearchConfigService()
	{
		return facetSearchConfigService;
	}

	
	public void setFacetSearchConfigService(final FacetSearchConfigService facetSearchConfigService)
	{
		this.facetSearchConfigService = facetSearchConfigService;
	}

	public BaseSiteService getBaseSiteService()
	{
		return baseSiteService;
	}

	public void setBaseSiteService(final BaseSiteService baseSiteService)
	{
		this.baseSiteService = baseSiteService;
	}

}

We have written the business logic which gets all the products older than specified days

Then we are iterating the product List and checking each product whether they have price row or not, If price row is not defined then we are adding such products to a list of deleting products.
then we are removing all such products.

After that we are calling the Solr full indexing to index only those products which have the price.

Since we need to define the query to get all the products older than specified days, we will create a new DAO Implementation class and interface as below

CustomProductsDAO.java
hybris\hybris\bin\custom\training\trainingcore\src\org\training\core\dao\CustomProductsDAO.java

  1. package org.training.core.dao;
  2.  
  3. import de.hybris.platform.core.model.product.ProductModel;
  4. import java.util.Date;
  5. import java.util.List;
  6.  
  7. public interface CustomProductsDAO
  8. {
  9.     public List<ProductModel> findAllProductsOlderThanSpecifiedDays(final Date oldDate);
  10. }
package org.training.core.dao;

import de.hybris.platform.core.model.product.ProductModel;
import java.util.Date;
import java.util.List;

public interface CustomProductsDAO
{
	public List<ProductModel> findAllProductsOlderThanSpecifiedDays(final Date oldDate);
}

CustomProductsDAOImpl.java
hybris\hybris\bin\custom\training\trainingcore\src\org\training\core\dao\impl\CustomProductsDAOImpl.java

  1. package org.training.core.dao.impl;
  2.  
  3. import de.hybris.platform.core.model.product.ProductModel;
  4. import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
  5. import de.hybris.platform.servicelayer.search.FlexibleSearchService;
  6. import de.hybris.platform.servicelayer.search.SearchResult;
  7. import java.util.Collections;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import org.training.core.dao.CustomProductsDAO;
  13.  
  14.  
  15. public class CustomProductsDAOImpl implements CustomProductsDAO
  16. {
  17.  
  18.     private FlexibleSearchService flexibleSearchService;
  19.  
  20.     @Override
  21.     public List<ProductModel> findAllProductsOlderThanSpecifiedDays(final Date oldDate)
  22.     {
  23.         final StringBuilder query = new StringBuilder("SELECT {pk} FROM {Product} WHERE {creationtime}<=?oldDate");
  24.     final Map<String, Object> params = new HashMap<String, Object>();
  25.         params.put("oldDate", oldDate);
  26.  
  27.         final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(query.toString());
  28.         searchQuery.addQueryParameters(params);
  29.         searchQuery.setResultClassList(Collections.singletonList(ProductModel.class));
  30.         final SearchResult searchResult = getFlexibleSearchService().search(searchQuery);
  31.         return searchResult.getResult();
  32.     }
  33.  
  34.    
  35.     public FlexibleSearchService getFlexibleSearchService()
  36.     {
  37.         return flexibleSearchService;
  38.     }
  39.  
  40.    
  41.     public void setFlexibleSearchService(final FlexibleSearchService flexibleSearchService)
  42.     {
  43.         this.flexibleSearchService = flexibleSearchService;
  44.     }
  45.  
  46. }
package org.training.core.dao.impl;

import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import de.hybris.platform.servicelayer.search.SearchResult;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.training.core.dao.CustomProductsDAO;


public class CustomProductsDAOImpl implements CustomProductsDAO
{

	private FlexibleSearchService flexibleSearchService;

	@Override
	public List<ProductModel> findAllProductsOlderThanSpecifiedDays(final Date oldDate)
	{
		final StringBuilder query = new StringBuilder("SELECT {pk} FROM {Product} WHERE {creationtime}<=?oldDate");
	final Map<String, Object> params = new HashMap<String, Object>();
		params.put("oldDate", oldDate);

		final FlexibleSearchQuery searchQuery = new FlexibleSearchQuery(query.toString());
		searchQuery.addQueryParameters(params);
		searchQuery.setResultClassList(Collections.singletonList(ProductModel.class));
		final SearchResult searchResult = getFlexibleSearchService().search(searchQuery);
		return searchResult.getResult();
	}

	
	public FlexibleSearchService getFlexibleSearchService()
	{
		return flexibleSearchService;
	}

	
	public void setFlexibleSearchService(final FlexibleSearchService flexibleSearchService)
	{
		this.flexibleSearchService = flexibleSearchService;
	}

}


Step 3

Define the above classes as spring beans in the *-spring.xml file as below
hybris\bin\custom\training\trainingcore\resources\trainingcore-spring.xml

  1. <bean id="customProductsDao" class="org.training.core.dao.impl.CustomProductsDAOImpl">
  2.         <property name="flexibleSearchService" ref="flexibleSearchService"/>
  3.     </bean>
  4.    
  5.     <bean id="productsRemovalJob" class="org.training.core.jobs.ProductsRemovalJob"
  6.         parent="abstractJobPerformable">
  7.         <property name="customProductsDao" ref="customProductsDao" />
  8.         <property name="modelService" ref="modelService" />
  9.         <property name="indexerService" ref="indexerService" />
  10.         <property name="facetSearchConfigService" ref="facetSearchConfigService" />
  11.         <property name="baseSiteService" ref="baseSiteService"/>
  12.     </bean>
<bean id="customProductsDao" class="org.training.core.dao.impl.CustomProductsDAOImpl">
		<property name="flexibleSearchService" ref="flexibleSearchService"/>
	</bean>
	
	<bean id="productsRemovalJob" class="org.training.core.jobs.ProductsRemovalJob"
		parent="abstractJobPerformable">
		<property name="customProductsDao" ref="customProductsDao" />
		<property name="modelService" ref="modelService" />
		<property name="indexerService" ref="indexerService" />
		<property name="facetSearchConfigService" ref="facetSearchConfigService" />
		<property name="baseSiteService" ref="baseSiteService"/>
	</bean>


Step 4

Write an impex to create a cron job instance as below
hybris\bin\custom\training\trainingcore\resources\impex\essentialdataJobs.impex

  1. $siteUid=apparel-uk
  2. INSERT_UPDATE ProductsRemovalCronJob; code[unique=true];job(code);xDaysOld;sessionLanguage(isocode);sessionCurrency(isocode);sites(uid)[default=$siteUid]
  3. ;productsRemovalCronJob;productsRemovalJob;5;en;EUR
$siteUid=apparel-uk
INSERT_UPDATE ProductsRemovalCronJob; code[unique=true];job(code);xDaysOld;sessionLanguage(isocode);sessionCurrency(isocode);sites(uid)[default=$siteUid]
;productsRemovalCronJob;productsRemovalJob;5;en;EUR

We are specifying old days as 5 so that 5 days older products will be considered.


Step 5

Write a impex into the same file to create a Trigger instance as below

  1. INSERT_UPDATE Trigger;cronjob(code)[unique=true];active;cronExpression
  2. #Fires at 10:15 AM everyday
  3. ;productsRemovalCronJob;true;0 15 10 * * ?
INSERT_UPDATE Trigger;cronjob(code)[unique=true];active;cronExpression
#Fires at 10:15 AM everyday
;productsRemovalCronJob;true;0 15 10 * * ?

Look at the relation between CronJob,Job and Trigger here.

While inserting ProductsRemovalCronJob Cron Job we are giving the reference of Job which should be same as spring bean id of the Job.

While inserting Trigger, we are giving the reference of ProductsRemovalCronJob which should be same as code defined while inserting ProductsRemovalCronJob

Also we have used Cron Expression in the Trigger which schedules it to run every day at 10:15 AM


Step 6

Do Update System by selecting the extension where we defined our job
Now Cron Job will be executed at the scheduled time automatically.

Note:
After Updating the system,we can run the below query to check the ServiceLayerJob created for the Job that we defined as a spring bean

  1. select * from {servicelayerjob} where {code} = 'productsRemovalJob'
select * from {servicelayerjob} where {code} = 'productsRemovalJob'

We should be able to see the Job details if everything is fine.


Step 7


Check the Products in HMC whose price not defined and they are X days old before Job runs

Search the same products after the Job runs successfully

We should not be able to see those products now.

See below screenshot which shows products only those which have prices and all other products have been deleted.

Products after cron job removal


How to Configure the CronJob manually ?

We can configure and run the cron job through HMC whenever we want to do it manually.

Steps for the same are as below

1)Log in to HMC
2)Go to System -> CronJobs
3)Type productsRemovalCronJob in Value Text Box for code then click on search
4)open productsRemovalCronJob
5) Go to Time Schedule tab ->set time in (Trigger text box) then save it.

If we want to start it immediately then Click Start CronJob now then our job will perform and display popup box with CronJob performed Result


How to execute the CronJob through Code rather than through Trigger ?

We can also execute the Cron Job through code rather than running it through Triggers as below

  1. ProductsRemovalCronJobModel  productsRemovalCronJobModel =modelService.create(ProductsRemovalCronJobModel.class);
  2.  
  3. // assign Job to CronJob
  4. ServicelayerJobModel  servicelayerJobModel = modelService.create(ServicelayerJobModel.class);
  5. servicelayerJobModel.setActive(true);
  6. servicelayerJobModel.setSpringId("productsRemovalJob");
  7. productsRemovalCronJobModel.setJob(servicelayerJobModel);
  8. modelService.save(productsRemovalCronJobModel);
  9. cronJobService.performCronJob(productsRemovalCronJobModel);
ProductsRemovalCronJobModel  productsRemovalCronJobModel =modelService.create(ProductsRemovalCronJobModel.class);

// assign Job to CronJob
ServicelayerJobModel  servicelayerJobModel = modelService.create(ServicelayerJobModel.class);
servicelayerJobModel.setActive(true);
servicelayerJobModel.setSpringId("productsRemovalJob");
productsRemovalCronJobModel.setJob(servicelayerJobModel);
modelService.save(productsRemovalCronJobModel);
cronJobService.performCronJob(productsRemovalCronJobModel);

In the above code, we have written a code to call the Cron job through CronJobService’s performCronJob() method

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on