惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
IT之家
IT之家
B
Blog
博客园 - 【当耐特】
H
Hackread – Cybersecurity News, Data Breaches, AI and More
AI
AI
S
SegmentFault 最新的问题
N
News | PayPal Newsroom
人人都是产品经理
人人都是产品经理
I
InfoQ
GbyAI
GbyAI
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
爱范儿
爱范儿
博客园 - 叶小钗
雷峰网
雷峰网
腾讯CDC
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
U
Unit 42
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
Cyberwarzone
Cyberwarzone
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Heimdal Security Blog
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google Online Security Blog
Google Online Security Blog
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
美团技术团队
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
S
Security @ Cisco Blogs
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
小众软件
小众软件
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

IT Jungle

GenAI Is The Death Of Deterministic Project Budgeting - IT Jungle PTC Adds Support For VS Code With Implementer 12.7 - IT Jungle As I See It: Push Back - IT Jungle IBM i PTF Guide, Volume 28, Number 21 - IT Jungle Progress And Frustration With IBM i Security, Fortra Finds - IT Jungle In The Trenches With: JAMS Software - IT Jungle Guru: Where’s The Table? - IT Jungle Lightedge To Start Selling IBM PowerVS to IBM i Customers - IT Jungle IBM i PTF Guide, Volume 28, Number 20 - IT Jungle Big Blue Unveils Bob Premium Pack For IBM i - IT Jungle Midrange Dynamics Sees Solid Git Adoption On IBM i - IT Jungle Guru: SQL Sequences In RPG Let Db2 Handle The Counting - IT Jungle From Green Screens To Smart Factories: Explaining DevOps To The Next Gen IBM i Developers - IT Jungle IBM i PTF Guide, Volume 28, Numbers 18 And 19 - IT Jungle Big Blue Is Still Talking About Future Power Processors, Which Is Good - IT Jungle Who To Consult With On Your Cloud Strategy, And Who To Manage It - IT Jungle Guru: DateTime Rules Of Thumb - IT Jungle i-Rays Performance Analyzer Now Ready for Prime Time, Omniology Says - IT Jungle CNX Adds AI To Valence Development Tool - IT Jungle Q&A With IBM’s New GM Of Power, Hillery Hunter - IT Jungle When IBM i Skills Become A Resilience Risk - IT Jungle Guru: Load A Varying-Dimension Array With One SQL Fetch - IT Jungle You Have To Speak IBM’s Language If You Want To Be Heard - IT Jungle Raz-Lee Revs iSecurity Suite With 2026 Updates - IT Jungle The Big Easy: Connecting The Dots On Big Blue’s AI Strategy For IBM i - IT Jungle From Migration To Maturity: The Cloud Reality For IBM i Shops - IT Jungle COMMON Dances To A Fresh New Tune In New Orleans - IT Jungle Eradani Touts Native Git Connection As AI Tools Spread - IT Jungle IBM i PTF Guide, Volume 28, Number 17 - IT Jungle Power Systems Still Waiting For The GenAI Bump - IT Jungle The IBM i and the Hybrid Cloud World: Things To Keep In Mind - IT Jungle CData Adds Db2 for i Support to CDC Tool - IT Jungle As I See It: The Cost of Having Ethics - IT Jungle Brace Yourself: Another Power Systems Price Hike Coming May 1 - IT Jungle Updates Announced for IBM i BRMS And SMTP Email Client - IT Jungle AI Will Be Front And Center At POWERUp 2026 Next Week - IT Jungle IBM i PTF Guide, Volume 28, Number 16 - IT Jungle Spring IBM i Tech Refreshes Will Come A Bit Later This Year - IT Jungle You Are Much More Than Power Systems, And So Are We - IT Jungle Startup Seeks The “Golden Path” for IBM i Modernization - IT Jungle What Can IBM Do To Make The Future Power S1112 Mini System Compelling? - IT Jungle IBM i PTF Guide, Volume 28, Number 15 - IT Jungle Bob 1.0 Users Bugged By Lack Of One Feature - IT Jungle Here Come The AI-Based Code Modernization Offerings - IT Jungle Guru: Cohesion First – What A Procedure Should Be Responsible For - IT Jungle IBM Offers Trade-Ins On Storage To Grease The Upgrade Skids - IT Jungle IBM i PTF Guide, Volume 28, Number 14 - IT Jungle What IBM i Ideas Are Cooking In IBM’s Ideas Portal? - IT Jungle Early Bob Excels In Medhost IBM i Tryout - IT Jungle Counting The Cost Of AI Inference – And Projecting It Far Out - IT Jungle IBM i PTF Guide, Volume 28, Number 13 - IT Jungle The Next Generation Of IBM i Talent in GenAI Action - IT Jungle
Guru: Single Threading A Program Execution - IT Jungle
Chris Ringer · 2026-06-15 · via IT Jungle
  • June 15, 2026

    A paceline in cycling is a formation where all the cyclists ride in a single file line and the lead bike is pulling the group along as everyone else is drafting behind. Eventually the lead bike will drift to the side and to the back of the line, and the next bike will take the lead for the group.

    If a spirited cyclist leaves the paceline and goes alone, all the aerodynamic benefits of drafting are lost.

    Likewise, at my organization, we have a CL job that is submitted hourly throughout the day every day. Normally the submitted job completes before the next job submits. We never want two of these jobs running simultaneously (“leaving the paceline”). In small “mom and pop” shops, each job could be submitted to a new single threaded JOBQ or the existing JOBQ could be made single threaded. But in a larger company, perhaps beholden to SOX, JOBQ changes could require extensive regression testing.

    Object Locking

    Another method to prevent two CL programs from running simultaneously is to use object locking via the ALCOBJ command with an *EXCL (exclusive) lock. Only one job on the system may hold an exclusive lock on a given object.

    Years ago, my first impulse was to just lock the *PGM object itself but this simply doesn’t work. The IBM documentation explicitly states “When ALCOBJ is executed to get an EXCL lock on a program (*PGM), only the program object description is locked. The program code is not locked exclusively. Therefore, the program may still be run by another user.” So my preference is to create a permanent data area object (CRTDTAARA) with the same name as the CL program and then lock that data area. Run this command to create a data area:

    CRTDTAARA DTAARA(TESTLIB1/OEM001) TYPE(*CHAR) LEN(100)
    VALUE('OEM001 data area for ALCOBJ *EXCL locks')
    TEXT('OEM001 ALCOBJ *EXCL data area') AUT(*USE)
    

    The Wait Is Finally Over

    And let’s walk through a sample CL program to demonstrate this locking technique.

    01 OEM001: PGM
    02 DCL var(&wkGotLock) Type(*Lgl ) Len(1)   Value('0')
    03 DCL var(&wkDlySecs) Type(*Dec ) Len(5 0) Value(2)
    04 DCL var(&wkTotSecs) Type(*Dec ) Len(5 0) Value(0)
    05 DCL var(&wkMaxSecs) Type(*Dec ) Len(5 0) Value(30)
    06 DoUntil Cond(&wkGotLock)
    07    ALCOBJ OBJ((TESTLIB1/OEM001 *DTAARA *EXCL)) WAIT(0) SCOPE(*JOB)
    08    MONMSG  MSGID(CPF1002) EXEC(Do)  /* Cannot allocate object &1. */
    09       DLYJOB DLY(&wkDlySecs)
    10       ChgVar Var(&wkTotSecs) Value(&wkTotSecs + &wkDlySecs)
    11       If Cond(&wkTotSecs *GE &wkMaxSecs) Then(Do)
    12          SNDPGMMSG MSG('WARNING: Could not get object Lock, exiting!')
    13          Return
    14       EndDo
    15       Iterate
    16    EndDo
    17    ChgVar Var(&wkGotLock) Value('1')
    18 EndDo
    19 ALCOBJ  OBJ((TESTLIB1/OEM001 *DTAARA *SHRRD)) WAIT(0) SCOPE(*JOB)
    20 DLCOBJ  OBJ((TESTLIB1/OEM001 *DTAARA *EXCL)) SCOPE(*JOB)
    21 /* do business logic here ... */
    22 DLCOBJ  OBJ((TESTLIB1/OEM001 *DTAARA *SHRRD)) SCOPE(*JOB)
    23 EndPgm 
    

    Let’s walk through the code.

    Line 01: The start of the CL program.

    Line 02: A Boolean variable to indicate if we got the exclusive object lock.

    Lines 03 – 05: Variables for the delay seconds when cannot lock the object, total seconds delayed so far and maximum seconds to delay.

    Line 06: A DO Loop when attempting to lock the data area.

    Line 07: Attempt to get exclusive lock on the data area and try for 0 seconds (no delay).

    Line 08: Message ID CPF1002 is thrown when “Cannot allocate object “.

    Line 09: Delay the job two seconds. As an alternative you may wish to delay for a fraction of a second with usleep.

    Line 10: Calculate the total delayed seconds so far.

    Line 11: If the maximum wait seconds is reached, will exit the program (or whatever you want to do).

    Line 12: Write a helpful message to the job log.

    Line 13: Exit the program.

    Line 14: End of IF statement.

    Line 15: Loop again.

    Line 16: End of MONMSG.

    Line 17: Got the exclusive lock. Will cause DO loop to exit.

    Line 18: End of the DO loop.

    Line 19: Get a second lock on the same object, this time a “shared read” (source: Ernie Malaga circa early 1990s). This will allow other jobs (and users) to view the object attributes and the data area contents. Retaining an exclusive lock any longer than necessary feels a bit harsh to me. Other jobs (and users) are unable to see any of the object attributes when an exclusive lock is held (see figure below).

    Line 20: Release the *EXCL lock (but still hold the *SHRRD lock). For a batch job, this statement is not necessary since all locks are automatically released when the job ends.

    If you set a debug breakpoint on this statement and run command WRKOBJLCK TESTLIB1/OEM001 *DTAARA, you can see the two locks:

    Line 21: Do the core business logic here.

    Line 22: Release the *EXCL lock. Now the next job in line may attempt to get the *EXCL lock.

    Line 23: Exit the program.

    If you CALL the CL program in debug from two different sessions and step through, you can see how the two jobs deal with the exclusive object lock.

    Well, that’s it for now. I hope you’re able to apply this technique down the road. Thanks for reading my tech tip and until next time, keep coding!

    Chris Ringer began coding RPG programs in 1989, and after a recent unexpected but valuable detour to C# is happy to be back in the IBM world. In his spare time he enjoys cycling and running – and taking the family dog Eddie for walks.

    RELATED STORIES

    Guru: Decoding Base64 ASCII

    Guru: A Faster Way To Sign A JWT

    Guru: Web Concepts For The RPG Developer, Part 4

    Guru: Web Concepts For The RPG Developer, Part 3

    Guru: Web Concepts For The RPG Developer, Part 2

    Guru: Web Concepts For The RPG Developer, Part 1

    Guru: The PHP Path To Victory, Part 1

    PHP Crash Course For RPG Developers

    Installing PHP on Your Laptop

    Debugging Server Jobs In Green Screen

    Tags: Tags: , , , , , ,