Search Java Code Snippets

  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.

#Java - Code Snippets for '#Synchronized' - 2 code snippet(s) found

 Sample 1. Singleton Class ( using private constructor , object initialization using static method, doubly checked , thread safe, synchronized , volatile reference )

class Singleton {
private static volatile Singleton instance = null;
private Singleton(){}
public static Singleton getInstance() {
if (instance == null) {
synchronized(Singleton.class) {
if (instance== null)
instance = new Singleton();
return instance;

   Like      Feedback     singleton   singleton class   volatile   private constructor    object initialization using static method   doubly checked    thread safe   synchronized block using class level lock   synchronized   synchronized block   class level lock  object initialization using getInstance

 Sample 2. Code Sample / Example / Snippet of org.apache.ace.client.repository.RepositoryObject.WorkingState

public WorkingState getWorkingState(RepositoryObject object) {
WorkingState result = null;
synchronized(m_lock) {
for (RepositorySet set: m_repositorySets) {
result = set.getWorkingState(object);
if (result != null) {
return (result == null) ? WorkingState.Unchanged : result;

   Like      Feedback      org.apache.ace.client.repository.RepositoryObject.WorkingState   synchronized

Subscribe to Java News and Posts. Get latest updates and posts on Java from
Enter your email address:
Delivered by FeedBurner