What's the best practice to ensure atomic read of a database table using JDBC?

前端 未结 6 1368
情深已故
情深已故 2021-02-19 06:26

I have an java application reading from a database table for jobs to process, and I may have multiple instances of this application running on different servers as each job is i

6条回答
  •  死守一世寂寞
    2021-02-19 07:23

    Lock the table using whatever mechanism is supported by your database server.

    For example, in Postgres it would be:

    LOCK yourtable;
    

    And it's your table for the duration of the transaction.

    Other databases will have something similar.

提交回复
热议问题