# Where to set @@allow\_concurrency= true

**URL:** <https://www.ruby-forum.com/t/where-to-set-allow-concurrency-true/66694>\
**Category:** Rails\
**Created:** [August 28, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/where-to-set-allow-concurrency-true/66694 "2006-08-28T14:30:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@amolla](https://www.ruby-forum.com/u/amolla)\
**Post date:** [August 28, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/where-to-set-allow-concurrency-true/66694/1 "2006-08-28T14:30:39Z")

</div>

Hi all,  
I would like to have a connection-per-thread in my rails app. According  
to the base.rb file, @@allow\_concurrency parameter mustbe set to true.  
I tried setting it both in environment.rb and ApplicationController but  
did not work. Where should I change that parameter so that it can work?

Thanks.

Ayhan

---

<div class="post-metadata">

**Author:** ![amolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@amolla](https://www.ruby-forum.com/u/amolla)\
**Post date:** [August 28, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/where-to-set-allow-concurrency-true/66694/2 "2006-08-28T17:09:10Z")

</div>

That kind of configuration should go in config/environment.rb, though  
you  
can’t just do ‘@@allow\_concurrency = true’ in the Initializer block. I’m  
not  
sure where this var is, I think ActiveRecord, so this would be the line  
you  
add (I’m pretty sure):

Rails::Initializer do  
…  
config.active\_record.allow\_concurency = true  
…  
end

Jason

---

<div class="post-metadata">

**Author:** ![amolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@amolla](https://www.ruby-forum.com/u/amolla)\
**Post date:** [August 28, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/where-to-set-allow-concurrency-true/66694/3 "2006-08-28T18:45:31Z")

</div>

On Aug 28, 2006, at 7:59 AM, Jason R. wrote:

> did not work. Where should I change that parameter so that it can  
> work?
> 
> Thanks.
> 
> Ayhan

```
Can you explain what you mean by "I would like to have a connection-

```

per-thread in my rails app" ? Rails doesn’t work that way as th  
framework as a whole is not thread safe\> So when it is served by  
mongrel , webrick or fcgi, requests are serialized when they are  
dispatched to rails so that only one runs at a time. So setting  
allow\_concurrency= true in a normal rails app will not get you  
anything. If you explain what you are trying to do I amy be able to  
shed some more light on it for you.;

-Ezra

---

<div class="post-metadata">

**Author:** ![amolla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@amolla](https://www.ruby-forum.com/u/amolla)\
**Post date:** [August 29, 2006, 9:56am UTC](https://www.ruby-forum.com/t/where-to-set-allow-concurrency-true/66694/4 "2006-08-29T09:56:28Z")

</div>

Thanks for your replies.  
In my tests in webrick server I found that all the threads are sharing  
a single database conenction. But I would like each thread to have its  
own connection.

I solved that with Jason’s advice by doing the the following in  
environment.rb

Rails::Initializer.run do |config|  
config.active\_record.allow\_concurrency = true  
end

Thanks.
