A crystal oscillator of the present invention includes: a substrate provided in a package; a heating device arranged as surrounding an internal area of the substrate on at least one of the surfaces of the substrate; a crystal resonator or a crystal element and an oscillation circuit unit provided in an area enclosed by the heating device; a thermosensitive element which detects a temperature in an area enclosed by the heating device; and a control unit for controlling a heating value applied to the heating device based on a detection result of the thermosensitive element.