Posts

Showing posts from August, 2015

Executing the BackGround Task

In Liferay we can exceute the background task asynchrously. The Background Task framework allows the developers to create and manage any kind of tasks that need to be run in a separated thread without the need of knowing anything about JAVA threading or concurrency Here the code ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Map taskContextMap = null; String taskName = null; String servletContextNames [] = new String[1] ; Portlet portlet = PortletLocalServiceUtil.getPortletById(request.getAttribute(WebKeys.PORTLET_ID).toString()); servletContextNames[0] = portlet.getContextName(); try { BackgroundTaskLocalServiceUtil.addBackgroundTask(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), taskName, servletContextNames,TestBackgroundTaskExecutor.class, taskContextMap,new ServiceContext()); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); }