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

前端 未结 6 1403
情深已故
情深已故 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:25

    if you want to ensure proper work in concurrent environment in your specific example you can use the server name.

    The table will look like:

    JobID  JobName  Server  Status
    -----  -------  ------- ---------
        1  Job_A    host-1  Completed
        2  Job_A    host-2  Working
        3  Job_B    host-3  Working
    

    if you have multiple instances on the same host add the process id too:

    JobID  JobName  Server  ProcessID  Status
    -----  -------  ------- ---------- ---------
        1  Job_A    host-1  1000       Completed
        2  Job_A    host-2  1000       Working
        3  Job_A    host-2  1001       Working
        5  Job_B    host-3  1000       Working
    

提交回复
热议问题