View Full Version : threads to handle requests
I have a question - In a plugin inside request method I am calling handleX method upon getting a request for X from the client. Is a thread spawned everytime handleX is called? Please let me know.
08-06-2012, 07:03 PM
You do not get a thread for each time handleX is called, however you DO get a separate thread for each time your plugin's request method is called. You may find Threading in Plugins (http://www.electrotank.com/docs/es5/manual/threading_in_plugins.htm) useful.
So, just to be sure, if I have two separate clients making request to the same plugin, both the requests would be handled in a different thread? Is that correct?
08-08-2012, 07:35 PM
Most likely yes. Plugins are multithreaded by default. You can turn the multithreading off but it will hurt the plugin's performance. You could also get them in the same thread if the requests arrived a few nanoseconds apart and one finished right when the second one was ready to be processed (the thread pool could randomly assign the same thread).
Best practice is to assume that your plugin might be processing two or more requests at the same time. Use concurrent data structures to avoid race conditions.
Powered by vBulletin® Version 4.1.6 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.