Question: In a cavity, the standing wave will constructively interfere with itself, so its energy gets higher while the oscillator is still vibrating. Since the vibration time is not a constant value, and sometimes the wall of the cavity absorbs some of the wave energy, the energy of a standing EM wave is probabilistic and follows Maxwell-Boltzmann distribution. Am I correct in the statement above?

---

Actually I'm thinking about the black-body radiation. To calculate the energy density in a cavity which is heated up to $T$, we assume that the cavity is a cube, and only standing wave can exist in it(Why?). First we need to calculate how many kinds of standing waves(how many different wave vectors) for one frequency $f$. This can be done with some mathematical tricks. And then we have to determine the energy of each wave $\overline{E(f)}$. And my question is, actually, why does this overline come from? Why is it an average energy, instead of a constant value?

Answer: 
Conservation of energy follows directly from Maxwell's equations, so if you convince yourself that energy isn't conserved when EM waves interfere, you've made a mistake, and you need to go back and figure out what your mistake was.

> 
> In a cavity, the standing wave will constructively interfere with itself, [...]
> 
> 
> 

Not true. If you work out the right-hand relationships for two EM plane waves traveling in opposite directions, you'll find that if the E fields are in phase, the B fields have opposite phases, and vice versa.
The constructive interference in a cavity doesn’t really make the energy higher. It is a way of seeing how a wave propagates in a confined space, the answer is there is a wave say going from left to right. At the same time there is another wave with the same frequency going from right to left. Those two waves constructively interfere with each other. Their total energy is set by excitation, so there is no increase of energy. The energy of a Resonance/oscillation never increases above its intial value set by excitation, unless excitation was done again which means extra energy was added to the system.

Resonance/oscillation occurs in cavity for particular frequencies that give rise to what is called resonance modes (for example TE111 is the lowest resonance mode in rectangular cavity). So the vibration time (the period of oscillation if that is what you meant) is constant.

If the walls are perfectly conducting, the resonance lasts for ever. If they are not perfect conductors, the energy of the oscillation (also called resonance mode) decreases until the resonance dies away.

I hope that was useful.