Results 1 to 4 of 4
- 11-19-2009, 05:43 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 1
- Rep Power
- 0
- 11-19-2009, 06:50 PM #2
Use a semaphore then. Or you can use a inner synchronize:
Java Code:private Object lock = new Object(); ... public void myFunction() { ... synchronized(lock) { ... } ... }Last edited by mrmatt1111; 11-19-2009 at 06:53 PM.
My Hobby Project: LegacyClone
- 01-20-2010, 07:48 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 90
- Rep Power
- 0
without using synchronized keyword you can do in this below way
public class Singleton {
// Private constructor prevents instantiation from other classes
private Singleton() {}
/**
* SingletonHolder is loaded on the first execution of Singleton.getInstance()
* or the first access to SingletonHolder.INSTANCE, not before.
*/
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
please go through this link for better idea : Using Synchronized keyword in Singleton Design Pattern
- 01-20-2010, 08:06 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 90
- Rep Power
- 0
Similar Threads
-
Are Local variables thread safe ?
By samson in forum Threads and SynchronizationReplies: 6Last Post: 12-21-2010, 02:34 PM -
Thread Safe Methods / Locks
By mrhyman in forum Threads and SynchronizationReplies: 16Last Post: 10-24-2008, 09:57 PM -
The safe way to stop a thread
By Java Tip in forum java.langReplies: 0Last Post: 04-09-2008, 06:31 PM -
Struts framework. Is this thread safe?
By JavaAl2 in forum Web FrameworksReplies: 1Last Post: 01-17-2008, 03:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks