I want to know what happens when a procedure is executed through a job and before it finishes is time for the job to call the next execution of the procedure. Here the job I created:
DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
(
job => x
,what => 'BEGIN PKG_DISTRIBUIDOR_SCHEDULER.PRC_DISTRIBUYE_TRANSACCIONES(5000); END;'
,next_date => to_date(sysdate,'dd/mm/yyyy hh24:mi:ss')
,interval => 'SYSDATE+30/86400'
,no_parse => FALSE
);
DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;
As you can see, the job is executed each 30 seconds. So if my procedure (PRC_DISTRIBUYE_TRANSACCIONES) delays more than 30 seconds, what does the job do in this case?
You will have to monitor dba_scheduler_job_run_details to see the status of the job run but you can easily use log_date to figure out which row is your row. Just select the row with log_date > sysdate when you called run_job. If that run succeeds, you will manually need to call drop_job. - use dbms_scheduler.
Stopping running jobs When a job is running and you want to stop it, you can run the STOP_JOB procedure as follows. BEGIN DBMS_SCHEDULER. stop_job (JOB_NAME => 'RMAN_INC'); END; STOP_JOB will attempt to gracefully stop a job.
Using DBMS_SCHEDULER to run things in parallel is by far the easiest and most common way to achieve this result. Of course it's going to consume more resources, that's what parallelism will inevitably do. Another, poorer option, is to use parallel pipelined table functions.
DBMS_JOB
The starting time for the next execution is determined when the current jobs is finished.
If you specify an interval as SYSDATE+30/86400
then it does not mean: "The job runs every 30 seconds."
It means: "The next jobs starts 30 seconds after the previous job has been finished."
DBMS_SCHEDULER
Immediately after a job starts, the repeat_interval
(e.g. FREQ=SECONDLY;INTERVAL=30
) is evaluated to determine the next scheduled execution time of the job. While this might arrive while the job is still running, a new instance of the job does not start until the current one completes. See About Setting the Repeat Interval
So it means: If a jobs last longer than 30 seconds then the new job will start immediately after the previous job has been finished.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With