To learn Clojure, I'm writing a system that could be compared to fold...@home. I have a database table of jobs that need to be done, where each row has an id, some data, and a status. The server that issues these jobs to clients is multi-threaded, and I want to ensure that it never issues the same job to two clients. I do a SELECT on the table to get the id and the data, and then an UPDATE to mark the row with that id as being checked out (the SELECT only grabs a row that has a not-checked-out status). The obvious problem with this, is that another thread might select the same row between the SELECT and UPDATE. I've thought of a few possibilities, but as I'm new to clojure, I was hoping for some advice on which would be best practice, and if I'm making bad assumptions.
1) I add a constraint to my UPDATE, so that it only updates rows that aren't checked out. If the execution of this statement returns a 0, I know there was a collision, and I SELECT a different row until the UPDATE returns 1. I fear that if this cycled once, it would cycle constantly until the server quieted down. 2) I perform all this SQL inside a dosync transaction. The call to JDBC's excuteUpdate would be the very last action, and the only side- effect. As I know very little about the inner workings of dosync, I fear I may be missing something obvious. 3) Perhaps some combination of #2, with autoCommit turned off, and/or rolling the database back to a saved state in the event of failure? Can't quite wrap my head around the best way to do this. Any thoughts or pointers? Help would be very much appreciated. Thanks! Sean -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en