× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: lock during update
  • From: Glenn Holmer <gholmer@xxxxxxxxxxxxxx>
  • Date: Tue, 21 Nov 2000 16:27:11 -0600
  • Organization: Weyco Group, Inc.
  • User-Agent: Mozilla/5.0 (X11; U; Linux 2.2.16 i686; en-US; m18) Gecko/20001107 Netscape6/6.0

I have a Java class that wants to read a file to get the last used
log number for the order file on an AS/400, increment it, then update
it.  The code I was using was:

       ControlFile.open(KeyedFile.READ_WRITE,
                        0,  // blocking factor
                        KeyedFile.COMMIT_LOCK_LEVEL_NONE);
       ControlFile.lock(KeyedFile.WRITE_ALLOW_SHARED_READ_LOCK);

       key = new Object[2];
       key[0] = "LE"; key[1] = "          ";
       rec = ControlFile.read(key);
       ConfirmationNumber = (BigDecimal)rec.getField("CNVA2");
       ConfirmationNumber = ConfirmationNumber.add(new BigDecimal("1"));
       rec.setField("CNVA2", ConfirmationNumber);
       ControlFile.update(key, rec);
     } catch (Exception e) {
       return (Object)e.getMessage();
     } finally {
       try {
         ControlFile.releaseExplicitLocks();
         ControlFile.close();

But this fails when a background job kicks in that processes the orders
that this same program writes, so it seems like "ControlFile.lock()" is
excessive.  An RPG programmer in our shop tells me that when you update
a record, that *record* is automatically locked.  But how do I ensure
that no one changes the CNVA2 field out from under me between the time
I read that record and the time I update it?  What the RPG programmer
explained to me is that when you do a CHAIN, you either update the record
or release it, but meantime it's yours.  What's the equivalent in Java?
(Sorry if this isn't clear to AS/400 programmers, I'm mainly a PC guy.)

-- 
____________________________________________________________
Glenn Holmer                          gholmer@weycogroup.com
Programmer/Analyst                       phone: 414.908.1809
Weyco Group, Inc.                          fax: 414.908.1601

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.