Waiting for an exclusive access to hashed file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
yserrano
Premium Member
Premium Member
Posts: 52
Joined: Thu Jan 31, 2008 1:23 pm
Location: Santo Domingo

Waiting for an exclusive access to hashed file

Post by yserrano »

Hello all,

I am using the FILELOCK statement to ask for an exclusive access to a hashed file and it is working very well.

Code: Select all

TargetName = "TargetFile"
Open TargetName TO HashedTargetFile Then
     FILELOCK  HashedTargetFile
...
But, in case the file is locked by another user I would like my routine to wait some seconds for the resource and then to ask again , in a loop, until the file is available.
Have you implemented something like that before? Do you have any suggestions?
I checked the "ON ERROR" and "LOCKED" statements to see if I could use them, but did not find anything related.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You found it, but did not realize it. The LOCKED clause is indeed what you want.

Code: Select all

$INCLUDE UNIVERSE.INCLUDE RECORDLOCKED.H
Equate MAXTRIES To 5    ; * maximum number of attempts
Equate NAPTIME To 1500  ; * 1.5 seconds

For Attempt = 1 To MAXTRIES
   FileLock HashedTargetFile
   Locked
      Nap NAPTIME
   End   ; * end of FileLock statement
While RecordLocked(HashedTargetFile, "DUMMY") <> LOCK$MY.FILELOCK
Next Attempt

* File lock could not be obtained.
If RecordLocked(HashedTargetFile, "DUMMY") <> LOCK$MY.FILELOCK
Then
   * Code here to handle "could not be file-locked".
End
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
yserrano
Premium Member
Premium Member
Posts: 52
Joined: Thu Jan 31, 2008 1:23 pm
Location: Santo Domingo

Post by yserrano »

I thought the FILELOCK function had an additional parameter to wait "automatically" a given time when the file was locked by another user/process.

I will use the code you provided, thank you.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There is no "time" component on the FILELOCK statement. Perhaps you are confusing this with the task synchronization locks, which are locked by a LOCK statement, which does have a timeout capability.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply