Thread-safe and performant way to return rows and then delete them

Hi all
I have a table containing rows to be processed by Java. These rows need to be returned to Java, then they willl be processed and sent to a JMS queue, then if that JMS operation is successful they need to be deleted from the Oracle table..
The current method is:
Java calls Oracle SP with 'numrows' parameter.
Oracle SP updates that number of rows in the table with a batch ID from a sequence, and commits.
Oracle SP returns the Batch_ID to Java.
Java then selects * from table where batch_id = XXXX;
Java sends messages to JMS. If JMS transaction is OK, Java deletes from table where batch_Id =xxxx and commits;
Clearly this isn't very efficient. What I would like to do is this:
Java calls Oracle SP with 'numrows' parameter
Oracle SP returns that many rows in a cursor and deletes them from the table simultaneously. Oracle SP does not open a new transaction - transaction is controlled from JAva.
Java writes to JMS. If JMS is OK, Java commits its DB transaction and thus the rows are deleted.
Therefore there's only a single DML operation - a DELETE.
The trouble is, this is not threadsafe - if I have two Java threads calling the Oracle SP, then thread #2 may return rows that thread #1 already got - because thread#1 has not yet committed its delete, and thread#2 can select those rows. Thread#2 will then lock waiting to delete them until thread#1 has finished its delete, then thread#2 will get "0 rows deleted". But Java will stlil have been sent those rows.
How can I engineer this method to be as efficient as possible while still being threadsafe? The key problem I'm having is that the DELETE operation doesn't prevent the rows being SELECTed by other threads - if there was a way to DELETE without committing but also immediately make those rows unavailable to other threads, that would work I think.
Any help much appreciated
Tom

Hi Tom,
You forgot to "mention" your version.
I'm not sure, but I believe [SKIP LOCKED|http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF01702] is safe to use. At least in 11.1. (I have used in both 9i and 10g where it was unsupported/undocumented)
There is of course always the boring way: A single thread.
Regards
Peter

Similar Messages

  • Is there a way to select all emails at once on the iPad and then delete them at one time?

    Is there a way to select all emails at once on the iPad and then delete them at one time?

    Tap on the edit button at  the top right of the email list. This will let you select the emails to delete, once all are selected, tap on the bottom right button that says delete to delete them all at once.

  • How do I archive emails in mail and then delete them from my inbox?

    I need to archive a bunch of emails for a project, and I know that if I put them in a mailbox and then delete them from my inbox, they're gone. So, what's the most efficient way to save 100s of emails that will eventually need to be filed within a project file?

    // Sample code
    List resList = new Vector();
    MyObject obj = null;
    while(rs.next()) {
        obj.setXXX(rs.getXXX(i));  // Get from the resultset and set to the object
        resList.add(obj);
    // At the end of the loop, you have a Vector of objects holding data.What do you mean by returning Strings separately?

  • I want to dump my photos from my phone onto my pc automatically, and then delete them from my phone. How do I do this?

    My wife and I both have an iphone 4s. We have been taking photos, and now the space on our phones is maxed out. Is there a way for me to automatically dump the photos onto my computer, and delete photos on my phone so that I hog up the space with photos? It seems like this shouldn't be complicated, but for some reason, I can't figure out how to copy the photos to my pc, and then delete them from my phone.

    Connect the phone to your computer and open whatever image capture application you have on the computer. An application you use to transfer photos from a camera to your PC should work with the iPhone. The computer will recognize the phone as a camera and allow you to copy photos to the computer, you can then keep or delete the photos from the iPhone.

  • I was saving the pictures on my phone onto my computer and then deleting them after they "saved", but after they were all deleted my computer decided not to save them. I went onto the Icloud website to look at them but cant. Help?

    I was saving the pictures on my phone onto my computer and then deleting them after they "saved", but after they were all deleted my computer decided not to save them. I went onto the Icloud website to look at them but cant. Help?

    There is nothing to help with.  There is no way to view the pictures in PhotoStream from the iCloud website.

  • I should know, but I don't. If I upload all of my photos to iCloud and then delete them off of my iPhone (for more storage space), will they all remain in iCloud or am I missing the point of iCloud?

    I should know, but I don't. If I upload all of my photos to iCloud and then delete them off of my iPhone (for more storage space), will they all remain in iCloud or am I missing the point of iCloud?

    Right now, there is no way to upload and access photos in iCloud. You need to import them to a computer if you want to be able to retrieve them later:
    PHOTO IMPORT IOS TO MAC/PC
    Cheers,
    GB

  • If I delete my songs from my "Downloads" folder, have them in my "Trash" and then delete them from my "Trash", will I still be able to play the songs on my iTunes or will they be deleted on my iTunes as well?

    I want to clear some space on my Mac since it is filling up and I don't have much room left on it. I want to delete all my songs from my "Downloads" folder and then delete them from my "Trash" to free up space however, I'm worried that if I do this then iTunes will not play any of the songs I deleted.
    Will I still be able to play my songs on iTunes even if they are not in my "Downloads" or "Trash" folders?
    Thank you.

    All tracks in iTunes (if you use default settings) should be in various artist and album folders in the main media folder in the iTunes folder. You can right click a track to reveal its location in Finder.  If there's a copy there then it doesn't really matter what you do with other copies.
    I have never downloaded from iTunes but I thought it placed files directly in the correct locations, or is this some other downloads folder to which you are referring?
    Normally if you download a file from another source and add it to iTunes by dragging it there, or using the Add To menu item, it places a copy of the file in iTunes.  You can discard the original, but if you're concerned you can check which copy iTunes is actually using as above.

  • Is it possible to save an iPhone back up and access the files later if needed?  I have a string of text sms and iMessages that I would like to save and then delete them from my phone.  Is this possible?

    I have a string of text sms and iMessages that I would like to save and then delete them from my phone, but gain access to them later if I need them.  I prefer to have the string with the date/time stamp vs copying and pasting into a doc or text file.  Is this possible?

    Not unless you buy an app that accesses data from an iTunes backup.  Check in the app store.

  • For some reason when I uploaded my photos from my i pad i have ended up with doubles and triples of many photos. How can I find them and then delete them?

    When I uploaded photos from my ipad to my desktop, for some reason I ended up with numerous doubles and triples. How can I find the duplicate photos and isolate them and then delete them?

    Pretty sure they are just jpegs from my canon 7D
    How did you get the photos from your Canon into your iPad?
    OT

  • Why can't anyone tell me how to remove all those little "!" in the left column all at once or at least sort them so I can mark them and then delete them?

    Why can't anyone tell me how to remove all those little "!" in the left column all at once or at least sort them so I can mark them and then delete them?

    This happens if the file is no longer where iTunes expects to find it. Possible causes are that you or some third party tool has moved, renamed or deleted the file, or that the drive it lives on has had a change of drive letter. It is also possible that iTunes has changed from expecting the files to be in the pre-iTunes 9 layout to post-iTunes 9 layout,or vice-versa, and so is looking in slightly the wrong place.
    Select a track with an exclamation mark, use Ctrl-I to get info, then cancel when asked to try to locate the track. Look on the summary tab for the location that iTunes thinks the file should be. Now take a look around your hard drive(s). Hopefully you can locate the track in question. If a section of your library has simply been moved, or a drive letter has changed, it should be possible to reverse the actions.
    Alternatively, as long as you can find a location holding the missing files, then you should be able to use my FindTracks script to reconnect them to iTunes.
    If, on the otherhand, you've been cleaning up your media from Explorer rather than iTunes and just want to eliminate the now broken links, use Tunes Folder Watch with its option to check for dead tracks on startup.
    tt2

  • Just configured my first iPad. Was sure I said no to iCloud , but now having tried out a few apps and then deleted them they seem to exist in iCloud. Why would this be ?.

    Just configured my first iPad. Was sure I said no to iCloud , but now having tried out a few apps and then deleted them they seem to exist in iCloud. Why would this be ?

    They don't exist in iCloud.
    iCloud is Apple's service for backups and App data storage / syncing.
    Purchased Apps, when removed from the iPad will still appear in your Purchased history, and you can still download them from "the" cloud which is just a generic term for Apple's App servers.
    Purchased Apps can de re-downloaded for free from the "cloud".  To allow you to do this Apple keeps a historic list of all your purchases so you can download them again should you ever need to without charging you again for them.
    This has nothing to do with the iCloud service you can choose not to use. For Calendars, Notes etc...
    It is independent un unrelated.

  • Can I save my photos from my iPhone to iCloud/iTunes, and then delete them from my iPhone to  free up space on my iPhone?I would  still like to keep them somewhere where they can  be accessed.

    Can I save my photos from my iPhone to iCloud/iTunes, and then delete them from my iPhone to  free up space on my iPhone?I would  still like to keep them somewhere where they can  be accessed.

    One option is to turn on iCloud Photo Library on the phone and go to Settings > iCloud > Photos and turn on "Optimize iPhone Storage." Then you don't delete the photo from the phone but it does occupy significantly less space. More information in iCloud Photo Library FAQ - Apple Support

  • How do I store photos on an external hard drive and then delete them from my MacBook hard drive

    I am sure this info is on the support site.  But I can't seem to find it.
    I want to move photos and movies (I'm using iphoto '11, 9.1.3) from my Mac Book hard drive to an external hard drive.
    What are the steps to take to move the photos and movies, and then safely remove them from the MacBook Pro hard drive?
    As an aside, are there any suggestions on external hard drives that work better with Mac (brands, size, Firewire vs USB, etc).
    Nothing sophisticated.  They're family photos, so they are important to me.
    Thanks
    AS

    Moving the iPhoto library is safe and simple - quit iPhoto and drag the iPhoto library intact as a single entity to the external drive - depress the option key and launch iPhoto using the "select library" option to point to the new location on the external drive - fully test it and then trash the old library on the internal drive (test one more time prior to emptying the trash)
    And be sure that the External drive is formatted Mac OS extended (journaled) (iPhoto does not work with drives with other formats) and that it is always available prior to launching iPhoto
    And backup soon and often - having your iPhoto library on an external drive is not a backup and if you are using Time Machine you need to check and be sure that TM is backing up your external drive
    The faster the connection the better,- Firewire or USB II would be the best
    THere are many good ones - I like Other World Computing products or Apple products
    LN

  • I have an IPad Model number A1475. I want to search all emails from one certain sender, Mark them all at one time without doing each one individually, and then delete them all at one push of a button. How do I do this?

    I have an IPad Model A1475. I want search all emails from a certain sender, Mark them all at one time and delete them at one time. How do I do this?

    Nobody knows? Not even administrators?
    Please it would be really nice to have help on that to take all the benefit of the remote app.
    Thank you very much in advance.

  • My goal is to backup my pictures and movies and then delete them from my computer to open up more space. What's the best way to do this?

    Let's say I let time machine backup my computer, then I delete most of my pictures (that are now backed up) to make room on my laptop's hard drive. The next time Time Machine backs up my computer will it overwrite the old backup with what it currently sees on my computer? Will it loose all of those pictures, because they're no longer on my laptop?

    ardenm58 wrote:
    Will it loose all of those pictures, because they're no longer on my laptop?
    Yes eventually or sooner by large changes to your boot drive.
    Read
    Most commonly used backup methods

Maybe you are looking for