I have a long running database task, which can vary from few minutes to few hours depending on the data to be processed. Since the background Task is dependent on the screen . I am calling an ExecutorService from Background Task,so even if the screen is closed the task is not interrupted.
At the end of the process , the ExecutorService process write summarized data into Excel.
First approach is write into separate folder then using fileuploadservice upload the excel file.
Second approach is read the bytes and add using fileloader service ( FileLoader Interface - CUBA Platform. Developer’s Manual )
I prefer the second approach and so i created a Service to perform the operation,but since the service is being called from Core Module , its throwing null pointer exception , where as if i manually call it via web module(screen) its working.
I cannot use AppContext Listener becuase users needs to call this Executor Service again and again using different input parameter.
How can i call Service from Core Module ? Also do you suggest any other better way other than ExecutorService,which cuba supports.
You should be able to call services from core the same way as from the client tier: by obtaining a reference using injection to a managed bean or using AppBeans.get() method.
Could you clarify what exception you get and how you invoke the service?
The reason I am doing this is becuase when the screen is closed ,the process gets terminated and I have a long process and so i call the ExecutorService.submit(Callable) and completes the service, but in the background the callable is triggering various subclasses and finally loadFiles.
I’m just wondering if the SecurityContext is present at the moment when the callable is submitted. Could you check it by printing AppContext.getSecurityContext() before submit?