www.webdeveloper.com
Results 1 to 2 of 2

Thread: static block in java

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    3

    static block in java

    what is static synchronized block in java.?

  2. #2
    Join Date
    Nov 2013
    Posts
    5
    Code:
    public class Example {
    	public static void main(String[] args) {
    		hye();
    		bye();
    	}
    	public static synchronized void hye() {   // synchronized method
    		System.out.println("hello");
    	}
    
    	public static void bye() {
    		synchronized (SyncExample.class) {   // synchronized block
    			System.out.println("goodbye");
    		}
    	}
    }
    staitic variables, members are loaded at the time of loading of the class not when the object will be initialized. One can access static method from other one without initializing the object of the class.
    synchronized means only one thread can enter at a time. Other threads will have to wait for the synchronized block or method.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles