Nuclear fusion is the main way for stars to generate energy. But we know that nuclear fission and fusion are not controlled, then it causes chain reaction and sudden explosion. But why in the case of stars it does not happen? I mean, that nuclear fusion happen in stars but it take few billion years to complete the amount of hydrogen. Is there any controlling mechanism? If no, what happens here?
Because in most stars, the pressure where nuclear burning takes place is proportional to temperature. In order for the nuclear reaction rate to increase, the temperature and hence pressure must increase. This would cause the gas to push out the layers above it, then to expand and cool.
Conversely, if the nuclear reaction rate fell, so would the temperature and pressure. The smaller pressure would allow the outer layers to move inwards, compressing the gas, heating it up and speeding up the nuclear reactions.
In this way the nuclear reaction rate (for hydrogen burning) can be kept almost constant. The small changes (increase) that occur during a star's main sequence life are driven by the increasing mean atomic mass as hydrogen turns to helium. This means you need a gradually higher temperature to maintain the same pressure.
Where the temperature and pressure are decoupled - for instance in the degenerate helium core of a low(ish) mass star near the red giant tip, where electron degeneracy pressure is independent of temperature, then runaway nuclear reactions can be initiated - the "helium flash".