Is there any alternative to synchronize class or method without using 'synchronized' keyword in java ?
Thanks, Mallikarjun Kokatanur
Is there any alternative to synchronize class or method without using 'synchronized' keyword in java ?
Thanks, Mallikarjun Kokatanur
You could use a "lockable" resource, such as a file.
You can also look at java.util.concurrent.locks which has more sophisticated locking.
Why don't you want to use synchronized?
You may want to look at the changes introduced with the concurrency package, to JDK 5.
http://java.sun.com/developer/technicalArticles/J2SE/concurrency/
Here are some of what is in the article:
It would help if you could elaborate on why you want to synchronize without using the synchronized
keyword. That is what it's for, after all.
You could do something like
void foo() {
if(x) { // or whatever
synchronize(this){
// do things
}
}
}
check out Lock
classes from java.util.concurrent.locks
package, which can be more flexible than sychronized methods