In order to improve an efficiency of energy detection for a spectrum sensing in cognitive radio (CR), this paper proposes a dynamic threshold optimization algorithm. The traditional energy detection algorithm uses a fixed threshold, and can't guarantee always the optimal sensing performance in any environment. The improvement for sensing performance need to minimize the undetected probability and the probability of false alarm, and it is dissimilar for different CR users to accept these two errors. We improve the traditional energy detection algorithm, and firstly introduce a preference factor to characterize CR users’ different requirements for these two errors, then, propose a dynamic threshold optimization algorithm by minimizing integrated detection error for different signal-to-noise ratio (SNR). The simulation results show that the proposed algorithm effectively reduces the integrated spectrum sensing error, and increases the probability of detection, especially in low SNR.