Saturday, June 26, 2010

Mutithreading in JAVA

How synchronization can be done for multithreading environment without using the "synchronized" keyword?

Use java.util.concurrent package

Lock mylock;
try
{
mylock.lock();
//critical section
}
finally{
mylock.unlock();
}

Also:
try a lock with a timeout trylock()
wait for some condition: condition.await()
these could come handy to avoid the deadlock situations.


Use java.util.concurrent package

Lock mylock;
try
{
mylock.lock();
//critical section
}
finally{
mylock.unlock();
}

Also:
try a lock with a timeout trylock()
wait for some condition: condition.await()
these could come handy to avoid the deadlock situations.


This can be achived using the volatile keyword this will be more useful. When multiple threads using the same variable .

No comments:

Post a Comment