zoukankan      html  css  js  c++  java
  • How to sync between processes rather than threads

    # lock across process
    e.g. Server handles request from different clients, there clients are essentially different processes, they could potentially write to the same piece
    of data(e.g. same records in table), so we need to make sure these access well synchronized.

    Since normal locking mechnism applies only to inter process(inter-threads), for normal lock from JDK won't work here.

    In this case, we need to use some medium from outside, which could be database records or some file on our hard disk.

    ## Using database records to be mutual exclusive

    CREATE OR REPLACE PROCEDURE BBDEV_DBO.Prcubblock(txtType IN CHAR, success OUT INT) IS
    intRecCount INT;
    BEGIN
         DELETE FROM UBBMSTLOCK WHERE dtlastmodified <= SYSDATE - 1/48;
         SELECT COUNT(*) INTO intRecCount FROM UBBMSTLOCK;
         IF (intRecCount = 0) THEN
             INSERT INTO UBBMSTLOCK VALUES (' ', 0, SYSDATE);
         END IF;
         IF (txtType = 'U') THEN
              UPDATE UBBMSTLOCK l
              SET l.txtlocktype = 'U', l.dtlastmodified = SYSDATE
              WHERE l.txtlocktype = ' ' OR l.txtlocktype = 'U';
              success := SQL%Rowcount;
         ELSIF txtType = 'S' THEN
              UPDATE UBBMSTLOCK l
              SET l.txtlocktype = 'S', l.dtlastmodified = SYSDATE
              WHERE l.txtlocktype = ' ' OR l.txtlocktype = 'S';
              success := SQL%Rowcount;
              IF (success > 0) THEN
                 UPDATE UBBMSTLOCK l
                 SET l.Intlockcount = l.Intlockcount + 1, l.dtlastmodified = SYSDATE
                 WHERE l.txtlocktype = 'S';
              END IF;
         ELSE
              success := 0;
         END IF;
         COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
         ROLLBACK;
         success := 0;
    END;
    /
    View Code



  • 相关阅读:
    ZT等占空比任意整数分频器的verilog语言实现
    并行输入的CRC32校验算法
    在Quartus II_10.1上跑一个用ModelSim仿真的简单例子
    QUARTUS II_10.1安装步骤
    ZT基于FPGA的CRC校验码生成器
    2013.09.17学习计划
    外设capsense的简单调用
    OrCAD学习笔记1
    路程之相遇问题
    ZT电路板设计软件及公司知识普及
  • 原文地址:https://www.cnblogs.com/glf2046/p/4740539.html
Copyright © 2011-2022 走看看