Home > Mobile >  Qt multithreaded write database system
Qt multithreaded write database system

Time:11-18

Windows 7 environment, qt multi-threaded database, written a received data is to create a thread to write database of problems;

After receiving the UDP data, send a signal to the main window, the main window to create a thread to write data

After a minute began card, find the reason is that thread creation is too much, stuck in that the

QMutex mymutex;
Void CTestThread: : run ()
{
Mymutex. The lock ();

//insert database content
QDebug () & lt; & lt;" Insert success: ";

Mymutex. Unlock ();
}

CodePudding user response:

Multithreading, lock, the documentary thread about efficiency, with a single thread

CodePudding user response:

The first lock is the consumption of resources, too much with the lock, it is better to single thread,
Concurrent threads in need to use,
To set up a single thread, a data is designed so that certainly is not reasonable, the thread is not excess the use of too much to consider using a thread pool to manage,

CodePudding user response:

Key or seeing you is all the time to create a database connection or a database connection pool, database connection could not be multiple threads to Shared, so usually we will write their own connection pooling, each time there is a new thread need to exclusive access to a free connection pool, pool size you can according to the actual situation, I usually 16 join processing, fast
  •  Tags:  
  • Qt
  • Related