Powered by Blogger.
Showing posts with label Threads. Show all posts
Showing posts with label Threads. Show all posts

Java - Synchronized block and method in detail

>> Saturday, September 20, 2014

Java is a multi-threaded programming language. So in every program multiple threads run in parallel to complete the program execution.At this point of time the results may differ or order of execution will change. To prevent the inaccuracy or inconsistency of data results, Java has provided 'synchronized' keyword to implement in 'synchronized block' and 'synchronized method'. The synchronized object won't allow two threads to access at the same time. So that one thread can't be reading while another updates it.The Second Thread should wait until the first is done.
Synchronized keyword in Java_JavabynataraJ

Read more..

MultiThreading or MultiTasking

>> Saturday, October 8, 2011

Multithreading / MultiTasking:

Let us assume a class containing three functions named as fun1,fun2 and fun3. If all are called once it may take more time to execute. 

In the above example fun2(), fun3() will be executed only after the complete execution of fun1().
Suppose fun1() is performing any input/output operations then at that time processor will be in the ideal state. If input/output operations take 60sec and also fun2() and fun3() will not be executed until 60sec are completed. To overcome this disadvantage the concept of multitasking is used.

There are two types of multitasking techniques.

                1.Process based multitasking
                2.Thread based multitasking


Read more..

What is the difference between sleep(), wait() and suspend()?

>> Wednesday, May 11, 2011

Thread.sleep() is used to suspend a thread execution for a specified time. or it sends the current thread into the "Not Runnable" state for some amount of time. The thread keeps the monitors it has aquired --

i.e. if the thread is currently in a synchronized block or method no other thread can enter this block or method. If another thread calls t.interrupt() it will wake up the sleeping thread.

Note that sleep is a static method, which means that it always affects the current thread (the one that is executing the sleep method). A common mistake is to call t.sleep() where t is a different thread; even then, it is the current thread that will sleep, not the t thread.

Read more..

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.