marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

Synchronization and Deadlock - Java in Hindi



जब दो Threads को समान Data को Share करना होता है, तब हमें ये तय करना जरूरी होता है कि एक Thread दूसरे Thread द्वारा Use किए जा रहे Data को Change नहीं करेगा।

उदाहरण के लिए मानलो कि Program का एक Thread किसी File से किसी Employee की Salary Read कर रहा है, जबकि दूसरा Thread उसी File में Employee की Salary को Update कर रहा है।

इस स्थिति में एक Thread दूसरे Thread द्वारा Use किए जा रहे Data को Corrupt कर सकता है। इस प्रकार की स्थितियों से बचने के लिए ये जरूरी है कि जब एक Thread किसी Data को Access कर रहा हो, तो उस समय कोई दूसरा Thread उसी Data को तब तक Access ना कर सके जब तक कि पहला Thread अपना काम पूरा नहीं कर लेता है।

जावा हमें ये सुविधा प्रदान करता है कि हम Multiple Threads के लिए समान Data पर Perform किए जाने वाले Actions को Coordinate किया जा सकता है। इस काम को पूरा करने के लिए Synchronized Methods या Synchronized Statements का प्रयोग किया जाता है।

एक ऐसा Object जिसके लिए Action को Coordinate किया जाना होता है, उस Object के Method के साथ synchronized Keyword का प्रयोग करना होता है। हम किसी synchronized Method को एक समय में केवल एक Object के लिए ही Call कर सकते हैं। इस Keyword के कारण एक समय में एक से ज्यादा Objects किसी Synchronized Method को Access नहीं कर पाते हैं और Threads आपस की Conflicts से बच जाते हैं।

जावा की हर Class व हर Object एक Monitor से Associated होता है। ये Monitor ही ये तय करता है कि किस प्रकार से एक Object या Class किसी Synchronized Method को Access कर सकेगा। ये Monitor तय करता है कि एक समय में केवल एक ही Object या Class किसी Synchronized Method को Access करे।

जब कोई Object किसी Synchronized Method को Invoke करता है, तब ये Monitor उस Method को तब तक के लिए Lock कर देता है, जब तक वह Object उस Synchronized Method को Use कर रहा होता है।

जैसे ही उस Object के लिए Synchronized Method का Execution पूरा होता है, Monitor उस Method को Release कर देता है, ताकि कोई दूसरा Object उस Method को Use कर सके।

ये Monitor उस समय भी Release हो जाता है, जब Synchronized Method wait() जैसे किसी Suspend Mode में जाने वाले Method को Call कर लेता है।

Synchronized Method से Associated Thread तब तक के लिए “NOT RUNNABLE” State में चला जाता है, जब तक wait() जैसा कोई Suspend Method Satisfy नहीं हो जाता है। जब ये Suspend Mode वाली Condition Satisfy हो जाती है, तब Thread Object “RUNNABLE” State में चला जाता है।

किसी Method को Synchronized करने के लिए हमें उस Method को निम्नानुसार Define करना होता हैः

?
1
2
3
public static synchronized void DisplayList(String name)  {
 // Synchronized Codes goes here.
}

Deadlock
एक ऐसा Application जिसमें Multiple Threads Multiple Resources को Use करते हैं, तब Deadlock की स्थिति पैदा हो सकती है। ये स्थिति उस समय पैदा होती है जब विभिन्न Threads Circular Dependency में पहुंच जाते हैं।

मानलो कि एक Thread A, किसी Thread B से किसी Synchronized Method के Release होने का Wait कर रहा है जबकि Thread B, Thread A से उसी Synchronized Method के Release होने का Wait कर रहा है।

इस स्थिति में दोनों Threads किसी Synchronized Method के Release होने का इन्तजार करते रहते हैं और दोनों Threads एक Infinite समय के लिए Wait State में चले जाते हैं। इसी स्थिति को Deadlock की स्थिति कहते हैं।

No comments:

Post a Comment