Large overestimation has been reported while predicting the thermal conductivity of hydrocarbons using an all-atom force field model in molecular dynamics (MD) simulations. Although it has been guessed as resulting from the high-frequency vibration of the hydrogen atoms and hydrogen constraints method is suggested to be employed to reduce the deviation, how hydrogen constraints affect the heat conduction and local structure of hydrocarbons in MD simulation is still not fully understood. In this work, the effect of hydrogen constraints on the prediction of thermal conductivity of n-decane in MD simulations with the all-atom force field is studied. The results show that the deviation of the thermal conductivity of n-decane can be narrowed down by 72.48 % in simulations if the hydrogen constraints with a SHAKE algorithm is employed. The analysis of heat flux decomposition indicates that employing hydrogen constraints can reduce the contribution of transport term and non-bonded interactions to the heat flux, which in turn can help improve the accuracy while predicting the thermal conductivity in MD simulations. Furthermore, results of the vibrational density of states show that hydrogen constraints can dismiss the high-frequency vibration mode of molecules, thus effectively reducing the overestimation of thermal conductivity of hydrocarbon systems in MD simulations. The findings of this work sheds light on the molecular mechanism of heat transfer in hydrocarbon systems.