Spring Batch Course Notes 13- Async Job


Synchronous execution will the previous task wait for the next task to run. In asynchronous executioner we can make the task run parallely instead of one task waiting on the other.

  • Need a POM Dependency of spring-batch-integration
  • Along with creating ItemProcessor we can create a new processor using the class AsyncItemProcessor.
    • Delegate the item processor object into the AsyncItemProcessor object using the the .delegate method.
    • Add TaskExecutor using the setTaskExecutor on the AsyncItemProcessor object. Setting it to new SimpleAsyncTaskExecutor should do the trick.
    • Set the AsyncItemProcessor into the job.
  • Create a new Object of the AsyncItemWriter class which taken in the data processed by the Async Item Processor and writes the data.
    • Delegate the custom ItemWriter object into the AsyncItemWriter object using the .delegate method.
    • Set the Task Executor as new SimpleAsyncTaskExecutor.
    • Add the AsyncItemWriter into the .writer method of the StepBuilder instead of the Custom Item Writer.

Difference between a Async Processing and multithreaded processing is that multithreaded processing processes the entire chunk in parallel due to this the order of records written will be random. But in case of Async Processing we run the processor and Writer parallely separately due this this the order of the output will not be impacted.

Oracle PLSQL Parse a Query to find the Tables used in the Query


The implementation that I have done is using REGEXP Functions of Oracle as below. This is a basic sample –

SET SERVEROUTPUT ON;
DECLARE
lv_clob CLOB := 'SELECT * FROM sch1.test1, sch2.test2 where sch1.test1.col1=sch2.test2.col2'; -- Your input query string
ln_count NUMBER := 0;
lv_substr VARCHAR2(1000);
ln_test NUMBER;
BEGIN
-- REPLACE CR and LF with Spaces
lv_clob := REPLACE(REPLACE(lv_clob,CHR(13),' '),CHR(10),' ')||' ';
-- REPLACE Multiple spaces with a single space
lv_clob := REGEXP_REPLACE(lv_clob,'\s+',' ',1,0,'i');
ln_count := REGEXP_COUNT(lv_clob,'(.*?)\s');
for i IN 1..ln_count
loop
lv_substr := NULL;
lv_substr := UPPER(TRIM(REGEXP_SUBSTR(lv_clob,'(.+?)\s',1,i,'i')));
IF(NOT(REGEXP_LIKE(lv_substr,'^([a-z]|[A-Z])(\d|\w|_|.)+$')))THEN
CONTINUE;
END IF;
IF(LENGTH(lv_substr)< 5)THEN CONTINUE; END IF; IF(lv_substr IN ('SELECT','FROM','WHERE','GROUP','WITHIN'))THEN CONTINUE; END IF; IF INSTR(lv_substr,'.') > 0 THEN
BEGIN
SELECT COUNT(1)
INTO ln_test
FROM dba_objects
WHERE owner =SUBSTR(lv_substr,1,INSTR(lv_substr,'.')-1)
AND object_name = SUBSTR(lv_substr,INSTR(lv_substr,'.')+1);
IF ln_test = 0 THEN
CONTINUE;
END IF;
EXCEPTION
WHEN OTHERS THEN
CONTINUE;
END;
ELSE
SELECT COUNT(1)
INTO ln_test
FROM dba_objects
WHERE owner ='PUBLIC'
AND object_name = lv_substr;
IF ln_test = 0 THEN
CONTINUE;
END IF;
END IF;
dbms_output.put_line(lv_substr);
END LOOP;
END;
/