Java

Java

Java

Topics on Semeru (Java) on IBM Z

 View Only
  • 1.  JZOS RecordReader and multiple threads

    Posted Thu January 19, 2023 05:27 AM
    Does JZOS RecordReader support multi-threading?

    I am trying to read from a RecordReader from within a Java parallel stream. I get an exception followed by a SC03 abend. Partial stack trace:

    Caused by: com.ibm.jzos.ZFileException: DD:????????: invalid JZOS BsamImpl handle; errno=-1 errno2=0xffffffff last_op=0
    errorCode=0x0
    at com.ibm.jzos.Bsam.readBlock(Bsam.java:203)
    at com.ibm.jzos.BsamVRecordReader.readNextBlock(BsamVRecordReader.java:88)
    at com.ibm.jzos.BsamVbsRecordReader.deblockSegmentsIntoRecord(BsamVbsRecordReader.java:73)
    at com.ibm.jzos.BsamVbsRecordReader.read(BsamVbsRecordReader.java:50)

    I have a lock around the actual read so it should be limited to one thread at a time, but the read is coming from a different thread to the thread that opened the dataset. It works OK when single threaded.

    My best guess is that JZOS doesn't support reading dataset from a different thread, but I can't find documentation to confirm that. If this is a JZOS limitation I will stop looking for the problem in my code. On the other hand, if this is supposed to work maybe I have a different problem.

    Can anyone confirm whether this is a JZOS limitation?

    Thanks

    Andrew Rowley

    ------------------------------
    Andrew Rowley
    ------------------------------


  • 2.  RE: JZOS RecordReader and multiple threads

    Posted Tue February 14, 2023 02:10 PM

    Hello Andrew, your post notification didn't make it to my news feed for some reason. I'll try to get someone to look into this.



    ------------------------------
    James Tang
    ------------------------------



  • 3.  RE: JZOS RecordReader and multiple threads

    Posted Tue February 14, 2023 07:24 PM

    Thanks James



    ------------------------------
    Andrew Rowley
    ------------------------------



  • 4.  RE: JZOS RecordReader and multiple threads

    Posted Tue February 21, 2023 11:32 AM
    Edited by Kristen Park Tue February 21, 2023 02:04 PM

    This is not a limitation and works in our testing. Can you provide us with the code or a similar sample to illustrate the problem you are seeing? If you cannot share that code in this forum you can open a support case.



    ------------------------------
    Gregory Lambert
    ------------------------------



  • 5.  RE: JZOS RecordReader and multiple threads

    Posted Wed February 22, 2023 04:54 AM

    Thanks for the reply.

    Based on your information I think I have identified the problem in my code... a thread is either reading after end of file or after the file is closed.

    However it is very useful to confirm that the RecordReader is expected to work when accessed from multiple threads - I had been doing it and hoping it was valid, but then had doubts when I ran into problems.

    I'm fairly confident now the problem is my code.

    Thanks

    Andrew Rowley



    ------------------------------
    Andrew Rowley
    ------------------------------



  • 6.  RE: JZOS RecordReader and multiple threads

    Posted Thu February 23, 2023 02:39 AM

    More testing today, it appears that the SC03 abend happens when the RecordReader is closed from a different thread.

    I was closing the RecordReader as soon as EOF was encountered because that avoided the problem of SC03 abends if you don't close the RecordReader. 

    My class that uses the RecordReader implements Closeable, so I think I will have to rely on that to perform the close and remove the close on EOF.

    However, it would be nice if z/OS Java avoided the SC03 abends completely. Ending a program without closing files is probably a common case and a SC03 abend is a bit ugly and un-Javalike. I think it would be better to do some sort of close automatically.

    (Maybe the SC03 when the program ends without closing a dataset is the same as my SC03, when Java attempts to close the dataset from some sort of shutdown thread???)



    ------------------------------
    Andrew Rowley
    ------------------------------



  • 7.  RE: JZOS RecordReader and multiple threads

    Posted Thu February 23, 2023 12:15 PM

    Yes, the documentation for the JZOS RecordReader close API states:

    Note: close() must be issued by the same thread as the factory method that creates the instance object (opening the dataset). Reading can occur on any thread.



    ------------------------------
    Gregory Lambert
    ------------------------------



  • 8.  RE: JZOS RecordReader and multiple threads

    Posted Thu February 23, 2023 08:07 PM

    Ahh.. OK I missed that in the documentation.

    In my defense that might be better as part of the usage information for the class rather than in the close method documentation.

    I also assumed that the first error was a read error, followed by a close error. But with multiple threads it was the other way around - the close error happened first.

    Thanks for the assistance. 



    ------------------------------
    Andrew Rowley
    ------------------------------