× 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: Re: lock during update
  • From: "Eric Merritt" <cyberlync@xxxxxxxxx>
  • Date: Tue, 21 Nov 2000 23:52:47 -0500

Hey Glen, Your RPG Buddy is right the equaivilent of a RPG CHAIN is the
KeyedFile.read(), Basically when this happens the entire record should be
locked untile you either update the record or move the cursor off the
record.


 I f I were you i would take the statement

>        ControlFile.lock(KeyedFile.WRITE_ALLOW_SHARED_READ_LOCK);

Out of your code and let the 400 due the locking for you. Its less resource
intensive and safer to (in my opinion). We have been doing this type of
thing for over a year now with no problems.

Hope this helps.
----- Original Message -----
From: Glenn Holmer <gholmer@weycogroup.com>
To: Java400 mailing list <JAVA400-L@midrange.com>
Sent: Tuesday, November 21, 2000 5:27 PM
Subject: lock during update


> 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
> +---


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

+---
| 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 ...

Replies:

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.