Superconducting materials inevitably suffer from the sudden change of temperature in the localized areas in practical applications, the concomitant thermal gradient might be detrimental to the performance. Critical current density is a key factor affecting the performance of superconductors, however, the effect of thermal gradient on the critical current density has not been identified. Here, combining the time-dependent Ginzburg-Landau (TDGL) equations and the heat transfer equation, the thermal gradient and magnetic field dependence of critical current density are systematically investigated and rationalized by exploring the behavior of vortex and magnetization. For lower magnetic fields, it is found that the thermal gradients strongly reduce the local surface barriers which inhibit vortex entry and movement, leading to a rapid deterioration of the current-carrying capability. Under moderate magnetic fields, the critical current density corresponding to higher thermal gradients decreases more slowly with increasing magnetic field, which results from the thermal gradient-induced entry and moving of vortices along the current direction. As the magnetic field continues to increase, the variation of critical current density transitions into a platform period and even slightly rises. The enhanced critical current is primarily attributed to the excess entry of vortices, which increases the surface barrier of the sample. With the further increase of the magnetic field, the critical current density continues to decrease due to increased magnetic field penetration. These results unveil the fundamental interplay among the thermal gradients, external magnetic field, vortex, magnetization, and critical current density, and provide a theoretical basis for understanding the heat-induced quench of the mesoscopic superconducting thin film in practical applications.