Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Thread optimization issue
RohitIti last edited by
i need help in deciding the correct way of managing threads.
Problem description :
I have a xml file containing some messages with id and a cycle time for each message.
The cycle time tells at what rate the messages should keep sending. Here lets take the total
number of messages as 100.
my requirement is that, i will get notification from outside (lets take it as some programme
triggering the message id) every time i get the message with id from outside i need to search
for that id in xml file and keep on sending the message to some other class for every cycle time of that message. This can be handled by timer and keep one sending the message.
but my problem is for every message am creating a new thread and sending which is not good.
can some tell me some thread optimization here so that it can be easily handled in later stages also.
<id>2</id> <msg>hello Qt</msg> <cycle>1000</cycle> . . .
class xmlparser() -------> reads xml file.
class MessageSender() -------> sends the message to class RecieverMessage.
class RecieverMessage() ----------> getmessage(id) , recieves the message,
searches the id in xmlparser and keep on creating thread and sends the message.
[andreyc EDIT]: Added @ around code.
How are you creating thread ? Did you inherit from QThread or using QRunnable ? You need to some kind of ThreadPool to manage number of threads what you create. There is QThreadPool and which works with only QRunnable. This can be used only if you don't want any signal/slot communication with your thread objects. Do you need to communicate back from threads to main UI ?
andreyc last edited by
[quote author="Dheerendra" date="1410348149"]There is QThreadPool and which works with only QRunnable. This can be used only if you don't want any signal/slot communication with your thread objects.[/quote]
It is not quite true.
You can inherit your class from "QObject and QRunnable":http://qt-project.org/forums/viewthread/22030/#104010 to get signal slot communication.
RohitIti last edited by
Thank you for your reply Dheerendra and andreyc,
I have inherited class from QThread and i need signal / slot communication.
so what kind of optimization i can do in this case