I know that in version 4.8, each HTTP request gets its own thread to run.
I am making a link checking application that processes a lot of HTTP requests in a while loop, and I notice in the Windows task manager that my application uses more than 1600 threads over time, and the number never decreases, only until it works the application . (I guess this is the reason.)
My question is, does QNetworkAccessManager ability to use a thread pool?
Or does he have the ability to clear his threads after completing his HTTP request?
This is the main loop:
while(!rpm_urlStack->isEmpty()) { QString url = rpm_urlStack->top(); //define the reply QNetworkReply *reply; rpm_urlStack->pop(); QString urlForReq(url); bool returnVal = true; QNetworkRequest request; request.setUrl(QUrl(urlForReq)); request.setRawHeader("User-Agent", USER_AGENT.toUtf8()); request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setRawHeader("Accept-Language", "en-us,en;q=0.5"); request.setRawHeader("Connection", "Keep-Alive"); QEventLoop loop; reply = m_networkManager->get(request); connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exit(); if(!loop.isRunning()) { loop.exec(); } RequestFinishedHandler(reply); // this is how I delete the reply object delete reply; } RequestFinishedHandler(QNetworkReply *reply) { if (reply->error() > 0) { QNetworkReply::NetworkError networkError = reply->error(); QString err = reply->errorString(); } else { QVariant vStatusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); QMutexLocker lock(_pMutex); // _pMutex defined as class member char *buffer; buffer = getCurrentDateTime(); QTextStream out(m_file); out << buffer << " " << _sCurrentUrl << "\n"; lock.unlock(); if(vStatusCodeV.toInt() == 200) { QString ApiResponse; QByteArray data; data=reply->readAll(); ApiResponse.append(QString::fromUtf8(data)); } } }
source share