Inter Thread Communication is one of the distinct facility in multi threading application development of java. In real world Inter Thread communication based applications of java works faster when compared to all the other applications in java.
Inter-thread communication is all about making synchronized threads communicate with each other. It is a mechanism in which a thread is paused running in its critical section and another thread is allowed to enter in the same critical section to be executed. It is implemented by following methods of Object class
wait() : Tells the calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify. 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.
There are two ways to create threads.
1. Create Threads implementing Runnable interface
2. Create Threads Extending Thread class
When to use Runnable interface
Use Runnable interface when your class is extending some other class. Since in Java mulitple inheritance is not possible we use Runnable interface to create Threads.
Universal Java Thread dump analyzer is a free tool that parses all formats of thread dumps and produces beautiful graphs,insightful metrics. It's intelligent thread dump analysis patterns identifies root cause for CPU spikes, Poor response time, unresponsive JVM, deadlocks, OutOfMemoryError.
Package java.util.concurrent.atomic
A small toolkit of classes that support lock-free thread-safe
programming on single variables.
A small toolkit of classes that support lock-free thread-safe
programming on single variables. In essence, the classes in this
package extend the notion of volatile values, fields, and
array elements to those that also provide an atomic conditional update
operation of the form:
boolean compareAndSet(expectedValue, updateValue);
Atomic classes are not general purpose replacements for
java.lang.Integer and related classes. They do not
define methods such as hashCode and
compareTo. (Because atomic variables are expected to be
mutated, they are poor choices for hash table keys.)
The specifications of these methods enable implementations to
employ efficient machine-level atomic instructions that are available
on contemporary processors.
java.util.concurrent.atomic
Class AtomicInteger
java.lang.Object
java.lang.Number
java.util.concurrent.atomic.AtomicInteger
An int value that may be updated atomically. See the
java.util.concurrent.atomic package specification for
description of the properties of atomic variables. An
AtomicInteger is used in applications such as atomically
incremented counters, and cannot be used as a replacement for an
Integer. However, this class does extend
Number to allow uniform access by tools and utilities that
deal with numerically-based classes.
int
incrementAndGet()
Atomically increments by one the current value.
Package java.util.concurrent.atomic Description
A small toolkit of classes that support lock-free thread-safe programming on single variables. In essence, the classes in this package extend the notion of volatile values, fields, and array elements to those that also provide an atomic conditional update operation of the form:
boolean compareAndSet(expectedValue, updateValue);
"The NetKernel Resource Oriented Computing (ROC) platform separates architecture from code. With ROC you can compose your architectural design independently from implementation code.
By keeping the details of code separate from high-level information architecture you gain:
freedom of choice in implementation language
rapid click-fit compositional development
long-term evolvable solutions
Threading and scheduling is managed by the microkernel so your code execution is efficiently optimised with linear scaling on multi-core without the need to learn new languages.
Something brand-new also comes from separating architecture and code. NetKernel provides system-wide caching of every area of your system. For free. No configuration.
NetKernel learns what information is reusable and reuses it. This makes NetKernel systems fast. Very fast."
"LMAX aims to be the fastest trading platform in the world. Clearly, in order to achieve this we needed to do something special to achieve very low-latency and high-throughput with our Java platform. Performance testing showed that using queues to pass data between stages of the system was introducing latency, so we focused on optimising this area. "
and it is still there even after the program finished. Let’s see if we can read that file once again, this time without creating it first.
Now, let’s see what happens, when we change the serialVersionUID value and try to deserialize once again our file. Change the line 2 in the class SerializeMe so that serialVersionUID contains now 2 instead of 1:
Exception in thread "main" java.io.InvalidClassException:
As you can see, this time the deserialization didn’t go well. ObjectInputStream complained about the serialVersionUID being changed.
How does he know that it changed? If serialVersinUID is static, then it should not have been serialized in the first place, and there should be no information about the previous value 1 during the deserialization, right? Well, serialVersionUID is an exception to the rule that “static fields don’t get serialized”.
Moreover, if there is no serialVersionUID officially declared in the class to be serialized, compiler automatically adds it with a value generated based on the fields declared in the class.
The deserialization of that object does not necessarily have to occur exactly after serialization. It can occur after a few months or on a completely different JVM
there is a chance that the class declaration has changed between serialization and deserialization.
It checks if the data read from the input stream is compatible with the current definition of the class.
when the visibility of a field changes, the serialVersionUID changes too.
sometimes you just want for some reason to forbid deserialization of old serialized objects,
you might tend to write it once for every serializable class ( or have it generated by the IDE ) and forget about it. WRONG !!!
If you write it once and don’t take care to update it when necessary, you loose all the merits of serialVersionUID.