Re: [Asterisk-java-users] Problems with concurrent java-threads answering incoming calls
Brought to you by:
srt
From: Stefan R. <ste...@re...> - 2008-02-14 18:14:52
|
Julien, thanks for your question. > Actually, I never posted any question on the ML but I am not so sure of > me on how Asterisk-Java handles threads. Think it's one instance of > AgiScript for each concurrent thread? So each instance variable access > (write?) has to be synchronized? Asterisk-Java actually supports both models: a) one shared instance for all calls b) one instance per call The preferred model is (a). It is also the default. In your example that would mean there is only one db connection that is shared by all calls. If you replace the db connection with a connection pool that is initialized in the contructor, that would match quite well. For instance fields the usual thread safety rules apply: - syncronized write access (if any, usually the instance members are final and initialized in the ctor) - local variables in the service() method for call specific things. Of cource your service method could also create new objects and delegate to them. Model (b) creates a new instance for each call so you don't have any shared state at the cost of "bootstrapping" you script for each call. To switch to model (b) you have to set the shareInstances property of your mapping strategy to false. See http://asterisk-java.org/development/apidocs/org/asteriskjava/fastagi/ResourceBundleMappingStrategy.html http://asterisk-java.org/development/apidocs/org/asteriskjava/fastagi/ClassNameMappingStrategy.html Independant of whether you use shared instances or not each call is always executed in its own thread. I hope this makes things a bit clearer. =Stefan -- reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: ste...@re... Jabber: ste...@re... WWW: http://www.reucon.com Steuernummern 215/5140/1791 USt-IdNr. DE220701760 |