Advertisement

Multi Threading Part-23 | Synchronization In Thread | Run time | Thread In Java Hindi - 164

Multi Threading Part-23 | Synchronization In Thread |  Run time | Thread  In Java Hindi - 164 Types of Synchronization:-

1)-Process based Synchronization
2)-thread based Synchronization.
thread based Synchronization:-

1.mutual exclusive:-

a.syncronized method.
b.synchronized block.
c.static synchronization

2.co-operation(inter thread commuination).
wait,notify,notifyAll



why Synchronization.?

1.To prevent thread interference.
2.To prevent consistency problem.

class A
{

void show(int x,int y)
{
1
fsdf
sdf
sdf
sdfsd
f
100
}

}



t1.show();

t2.show();

t3.show();


Locking

1)-implicit
2)-explicit


Inter-thread communication in Java

Inter-thread communication or Co-operation is all about allowing synchronized threads to communicate with each other.

Cooperation (Inter-thread communication) is a mechanism in which a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed.It is implemented by following methods of Object class:

wait()
notify()
notifyAll()
1) wait() method
Causes current thread to release the lock and wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.


The current thread must own this object's monitor, so it must be called from the synchronized method only otherwise it will throw exception.

Method Description
public final void wait()throws InterruptedException waits until object is notified.
public final void wait(long timeout)throws InterruptedException waits for the specified amount of time.

2) notify() method
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. Syntax:

public final void notify()

3) notifyAll() method
Wakes up all threads that are waiting on this object's monitor. Syntax:

public final void notifyAll()
Stay tuned with me for more upcoming Videos,
don't forget to subscribe my YouTube Channel and share your valuable comments in Comment section down below, i'll be happy t o help you all, your Surya ☺

For Industrial/Summer/Winter Training Please Visit:-
To download JDK click in this link:

To download Android Studio click in this link:


Download my you tube channel Android application from here-

Firebase Tutorial No-6 URl-


Firebase Tutorial No-1 URl-

Firebase Tutorial No-2 URl-

Firebase Tutorial No-3 URl-

Firebase Tutorial No-4 URl-

Write program url using Firebase Database-

Sqlite database tutorials part-1 url-


Sqlite database tutorials part-2 url-


Storage option url-


Internal Storage url-


External Storage url-


Shared Prefrences url-


Spinner Url-

CustomListView Url-


ListView In Android Studio Part-1


ListView In Android Studio Part-1

ListView In Android Studio Part-2 With EventHandling


ListView In Android Studio Part-3 With EventHandling


Firebase:-


How to Install Java Url-


GridLayout url-


TableLayout url-


RelativeLayout-




Linearlayout-



Connect on Socials:-

Facebook:-
Twitter:-
Google Plus:-
LinkedIn:-

Hindi

Post a Comment

0 Comments