Does a single thread need a lock?

< H2 > recently wrote a background management system based on springboot, which provides many interfaces to add, delete, modify and insert databases without manually creating any threads. I wonder if there will be problems if concurrency occurs < / H2 >
    Does
  1. need to be locked?
  2. Will
  3. collapse?
  4. Will the
  5. be oversold like a second kill?
Dec.08,2021

are you a novice? Each request in the concurrency is a thread. You don't need to create it manually. Tomcat will automatically create it for you. First figure out the memory model of java, and then take a look at the transaction isolation of the database.


your question is too general. As far as the third oversold issue is concerned, we must consider the problems of optimistic lock and pessimistic lock. In addition, you need to combine your business and MVC layering to determine the propagation attributes of the transaction.


first of all, every time there is a client request, there is a thread at the bottom of the Java to handle it, not a single thread.
then, if there are a lot of users requesting, Java will also have a lot of threads to access the database, which will be oversold.
Secret kill does not recommend locking, but uses token bucket or leaky bucket algorithm to solve the problem.


is it understood that multithreading can not only create threads through code, but also automatically allocate multiple threads through the thread pool, so the problem of multithreading must be considered, so locks must be added.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30c1f-2aa83.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30c1f-2aa83.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?