Hi Andrew,
sure, this is where resources come into play.
I assume that the batch consists of multiple jobs (and maybe other batches).
That would cover the more general case.
You are going to need a synchronizingnamed resource. The name doesn't play a role, but something that makes its role understandable would make sense.
Now you can create a resource either in scope GLOBAL (or some scope below, but it should be visible to the jobs that are going to allocate it).
From here you have two options:
1. Use a LOCK and UNLOCK job
2. Let the Master (the top level scheduling entity) allocate the resource and keep it until it is FINAL
In the first case you create a job that allocates the resource with the STICKY flag set. This job should run as the first job of your batch.
It should also lock the resource with an exclusive lock (X).
And you create another job that allocates the resource and runs as the last job of the batch. Again with lockmode Exclusive and the Sticky Flag set.
As a run program you can use 0 (just the number zero), which is basically a /bin/true without overhead.
The second option is easy. The master is converted into a job (with run program 0) because it needs to allocate the resource with exclusive lock.
Be sure to specify KEEP_FINAL as the keep option. This will guarantee that the resource is first released when all children are final.
There's another crucial detail to take care of. The first job that can run should wait for its master. Hence you'll need a dependency that telles the first job to wait until the master is JOB_FINAL.
This way it'll have to wait until the master was able to allocate the resource.
I hope that this all makes sense to you.
If not, please ask again and I'll try to answer it again a little more in detail.
Enjoy your weekend!
Best regards,
Ronald