Skip to content

How to Use

jialianglinjl edited this page Jun 22, 2018 · 36 revisions

Contents

"Hello world"

The following is a basic “Hello World” implementation of a resource definition:

public void helloWorld() {
	Entry entry = null;
	try {
		// Resource name that can identify the protected logic
		entry = SphU.entry("HelloWorld");
		/**
		 * BIZ Logic that need protection
		 */
	} catch (BlockException e) {
		/**
		 * Fail to enter, blocked by rules
		 */
	} finally {
		if (entry != null) {
			entry.exit();
		}
	}
}

or we can also use 'if' and 'else' to define resource:

public void helloWorld(){
  if(SphO.entry("HelloWorld")){
    try {
      /**
      *  BIZ Logic that need protection
      */
    } finally {
      SphO.exit();
    }
  }else{
   /**
	 * Fail to enter, blocked by rules
   */
  }
}

Clone this wiki locally