search

Home  >  Q&A  >  body text

java - 别人调用我接口,往我数据库里插数据问题,谢谢

局域网里,别人使用C#写的程序,开了4个线程,往我接口里插入4张不同表的数据,问题如下:

谢谢

PHP中文网PHP中文网2888 days ago528

reply all(5)I'll reply

  • PHPz

    PHPz2017-04-18 09:09:15

    Thank you, Chairman, for the invitation.
    The two methods mentioned by the Chairman are the same. They are both methods to prevent duplication. The main difference is that deduplication of primary keys or unique indexes can effectively solve the problem of duplicate insertions, while checking duplications in the program. Insertion, since these two operations are not atomic, it still cannot prevent requests from being inserted between your query and the insertion, so there is still a risk of duplication.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:09:15

    As long as the database can handle the amount of requests, you can use the unique index of the database. You can also use redis to make uniqueness judgments at the application layer.

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:09:15

    I feel that the focus of this question is not on data deduplication, but on why the student initiated a retry when he did not receive a message that the operation failed.
    It is recommended to use an interceptor to log to see the processing time of each request.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:09:15

    The calling party should wait for the request response before doing the next operation. For example, the request timeout can be set shorter.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:09:15

    The simplest and most effective method is to build a unique index, without considering performance issues for the time being.
    If we really encounter a database bottleneck, it is estimated that the architecture will not be what it is now.

    reply
    0
  • Cancelreply