I want to know if our Shastras mention how to control uncontrollable or deviating thoughts especially during prayer,Japa or Sadhna?
What you are experiencing is a symptom of not following Saadhna or Dhyaan routine properly. I came across this issue in Complete Works of Swami Vivekananda earlier and would like to suggest you to read in detail Chapter 1.4.21: PRACTICAL RELIGION: BREATHING AND MEDITATION on how to practice meditation with best results.
In Shrimadbhagvadgita : Chapter 6 : Dhyaan yog, Bhagwan Krishna talks in detail about credentials of a Yogi and how to become one. I will share few shlokas here for reference, but would advise to go through complete chapter for proper understanding.
Step 1: Place and Posture
शुचौ देशे प्रतिष्ठाप्य स्थिरमासनमात्मनः। नात्युच्छ्रितं नातिनीचं चैलाजिनकुशोत्तरम्।।6.11।।
In a clean spot, having established a firm seat of his own, neither too high nor too low, made of a cloth, a skin and Kusa-grass, one over the other.
तत्रैकाग्रं मनः कृत्वा यतचित्तेन्द्रियक्रियः। उपविश्यासने युञ्ज्याद्योगमात्मविशुद्धये।।6.12।।
There, having made the mind one-pointed, with the actions of the mind and the senses controlled, let him, seated on the seat, practise Yoga for the purification of the self.
समं कायशिरोग्रीवं धारयन्नचलं स्थिरः। संप्रेक्ष्य नासिकाग्रं स्वं दिशश्चानवलोकयन्।।6.13।।
Let him firmly hold his body, head and neck erect and still, gazing at the tip of his nose, without looking around.
प्रशान्तात्मा विगतभीर्ब्रह्मचारिव्रते स्थितः। मनः संयम्य मच्चित्तो युक्त आसीत मत्परः।।6.14।।
Serene-minded, fearless, firm in the vow of a Brahmachari, having controlled the mind, thinking of Me and balanced in mind, let him sit, having Me as his supreme goal.
Step 2 : Balanced food, Balanced sleep, Balanced exercise
नात्यश्नतस्तु योगोऽस्ति न चैकान्तमनश्नतः। न चातिस्वप्नशीलस्य जाग्रतो नैव चार्जुन।।6.16।।
Verily Yoga is not possible for him who eats too much, nor for him who does not eat at all, nor for him who sleeps too much, nor for him who is (always) awake, O Arjuna.
युक्ताहारविहारस्य युक्तचेष्टस्य कर्मसु। युक्तस्वप्नावबोधस्य योगो भवति दुःखहा।।6.17।।
Yoga becomes the destroyer of pain for him who is moderate in eating and recreation (such as walking, etc.), who is moderate in exertion in actions, who is moderate in sleep and wakefulness.
Step 3 : Determination, Focus
तं विद्याद् दुःखसंयोगवियोगं योगसंज्ञितम्। स निश्चयेन योक्तव्यो योगोऽनिर्विण्णचेतसा।।6.23।।
Let that be known by the name of Yoga, the severance from union with pain. This Yoga should be practised with determination and with an undesponding mind.
सङ्कल्पप्रभवान्कामांस्त्यक्त्वा सर्वानशेषतः। मनसैवेन्द्रियग्रामं विनियम्य समन्ततः।।6.24।।
6.24 Abandoning without reserve all desires born of Sankalpa (thought and imagination) and completely restraining the whole group of the senses by the mind from all sides.
शनैः शनैरुपरमेद् बुद्ध्या धृतिगृहीतया। आत्मसंस्थं मनः कृत्वा न किञ्चिदपि चिन्तयेत्।।6.25।।
6.25 Little by little let him attain to ietude by the intellect held firmly; having made the mind establish itself in the Self, let him not think of anything.
यतो यतो निश्चरति मनश्चञ्चलमस्थिरम्। ततस्ततो नियम्यैतदात्मन्येव वशं नयेत्।।6.26।।
6.26 From whatever cause the restless and unsteady mind wanders away, from that let him restrain it and bring it under the control of the Self alone.
Step 4 : Continuous Practice
युञ्जन्नेवं सदाऽऽत्मानं योगी विगतकल्मषः। सुखेन ब्रह्मसंस्पर्शमत्यन्तं सुखमश्नुते।।6.28।।
6.28 The Yogi, always engaging the mind thus (in the practice of Yoga), freed from sins, easily enjoys the Infinite Bliss of contact with Brahman (the Eternal).
Arjun asks pretty much the same question you have
योऽयं योगस्त्वया प्रोक्तः साम्येन मधुसूदन।
एतस्याहं न पश्यामि चञ्चलत्वात् स्थितिं स्थिराम्।।6.33।।
6.33 Arjuna said This Yoga of eanimity taught by Thee, O Krishna, I do not see its steady continuance, because of the restlessness (of the mind).
चञ्चलं हि मनः कृष्ण प्रमाथि बलवद्दृढम्।
तस्याहं निग्रहं मन्ये वायोरिव सुदुष्करम्।।6.34।।
6.34 The mind verily is restless, turbulent, strong and unyielding, O Krishna: I deem it as difficult to control it as to control the wind.
Bhagwan Krishna re-iterates that continuous practice and commitment is required.
असंशयं महाबाहो मनो दुर्निग्रहं चलं।
अभ्यासेन तु कौन्तेय वैराग्येण च गृह्यते।।6.35।।
6.35 The Blessed Lord said Undoubtedly, O mighty-armed Arjuna, the mind is difficult to control and restless; but by practice and by dispassion it may be restrained.