Every object in Java code has one lock, which is useful for ensuring that only one thread accesses critical code in the object at a time. This synchronization helps prevent the object's state from getting corrupted.
Tutorial Details:
Thread synchronization
Every object in Java code has one lock, which is useful for ensuring that only one thread accesses critical code in the object at a time. This synchronization helps prevent the object's state from getting corrupted. If a thread has obtained the lock, no other thread can enter the synchronized code until the lock is released. When the thread holding the lock exits the synchronized code, the lock is released. Now another thread can get the object's lock and execute the synchronized code. If a thread tries to get the lock of an object when another thread has the lock, the thread goes into a blocked state until the lock is released.
Synchronized
You can use the synchronized keyword to declare a method as synchronized. This method cannot be accessed by multiple threads simultaneously. The synchronized keyword can also be used to mark a block of code as synchronized. For this, the argument passed should be the object whose lock you want to synchronize on.
When the wait() method is invoked, a thread releases the lock on an object and moves from the running state to the waiting state. The notify() method is used to signal one of the threads waiting on the object to return to the runnable state. It is not possible to specify which of the waiting threads should be made runnable. The notifyAll() method causes all the waiting threads for an object to return to the runnable state.
Read
Tutorial at: Click here to view the tutorial
Rate Tutorial: Java General Java Thread synchronization Tutorial
View Tutorial: Java General Java Thread synchronization Tutorial
Related
Tutorials:
Programming Java threads in the
real world, Part
1 - JavaWorld -
September 1998
Programming Java threads in the
real world, Part
1 - JavaWorld -
September 1998 |
Programming Java threads in the
real world, Part
2 - JavaWorld -
October 1998
Programming Java threads in the
real world, Part
2 - JavaWorld -
October 1998 |
Programming Java threads in the
real world, Part
9 - JavaWorld
June 1999
Programming Java threads in the
real world, Part
9 - JavaWorld
June 1999 |
Double-checked
locking: Clever, but broken - JavaWorld February
2001
Double-checked
locking: Clever, but broken - JavaWorld February
2001 |
Master Java with these introductory books - JavaWorld May 2001
Master Java with these introductory books - JavaWorld May 2001 |
Can double-checked locking be fixed? - JavaWorld May 2001
Can double-checked locking be fixed? - JavaWorld May 2001 |
Avoid synchronization
deadlocks
Avoid synchronization
deadlocks |
Can ThreadLocal solve the double-checked locking
problem?
Can ThreadLocal solve the double-checked locking
problem? |
I want my AOP!, Part 3
I want my AOP!, Part 3 |
Achieve strong performance with threads,
Part 1
Achieve strong performance with threads,
Part 1 |
Achieve strong performance with threads,
Part 2
Achieve strong performance with threads,
Part 2 |
Very
interesting
Very
interesting |
elegant turnaround
elegant turnaround |
Fixing the Java Memory Model, Part 2
Writing concurrent code is hard to begin with; the language should not make it any harder. While the Java platform included support for threading from the outset, including a cross-platform memory model that was intended to provide \"Write Once, Run Anywh |
JDBC scripting, Part 2
JDBC scripting, Part 2
Programming and Java scripting in JudoScript
Summary
JudoScript is a rich functional scripting language, and an easy and powerful general programming and Java scripting language.
JudoScript's power comes from its synergy of |
The ABCs of Synchronization, Part 1
Threads may execute in a manner where their paths of execution are completely independent of each other. Neither thread depends upon the other for assistance. For example, one thread might execute a print job, while a second thread repaints a window. And |
Concurrency in JDK 5.0
Concurrency in JDK 5.0
JDK 5.0 added major new support for developing concurrent applications, including JVM changes, new low-level synchronization utilities, and higher-level, thread-safe, high-performance concurrency classes such as thread pools, concu |
Servlet Essentials
This document explains the concepts of Java Servlets and provides a step-by-step tutorial for writing HTTP Servlets with complete source code for the example Servlets. The tutorial and the other chapters cover all facets of Servlet programming from a ... |
JavaServer Pages Technology - Documentation
Sun's tutorial for Java Server Pages that provide a good introduction to design web pages with JSP. |
Core Java Interview Questions!
Core Java Interview Questions!
Core Java Interview Questions
Question: What is transient variable?
Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written |
|
|
|