java - Thread synchronized block with Class itself -


I think that creating a synchronized-block following use as Thredmolik class. Class is unique but when I have prepared several threads with multiple threads, <+> get () method I have come to know that many inconsistent states have been created. So why is not the thread synchronized with ThreadMyClass.class example?

  public Thredmoylclas {public Object get () {synchronized (ThreadMyClass.class) {/ object returns received}}} public static final Object lock = new Object ();  

When I ThreadMyClass.class code> has lock object, then everything is working fine.

Updated: Here's my entire code piece The example building block is applied more than once.

  public static XMPPInterface getInstance () throws XMPPException {if (instance == null) synchronized {(XmppInterface.class) {if (instance == null) {// Create an instance}}} Return example; } Are synchronized  

Well, you class There were no examples, which was similar to a stable synchronized method

You can use the synchronize example method to synchronize your class instance. You can use.

Otherwise, a object that synchronization is used to lock in the code, object , synchronization strategies your remaining static and instance methods Will be left in "Free".


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -