Skip to main content

Posts

Showing posts from July, 2012

Volatile keyword in JAVA

I've found an interesting and easy to understand explanation about volatile keyword, it came with an example but it was wrong so I've corrected it. A volatile variable does not have a copy maintained in the local memory of the thread (on the stack). All changes to the volatile variable (caused by multiple threads) are flushed out to the heap memory (visible from all threads). Hence volatile variable values remain consistent for all threads.  On the other hand, for other instance variables, each java thread maintains a local copy on the stack. Multiple threads may modify this local copy of the instance variable and hence inconsistent values may be visible for multiple threads.  For preventing this condition, we synchronize. During synchronization, a lock is first taken on the object monitor. Then the thread reads the state from the main memory and flushes its internal state. Subsequently, the synchronized code block/method code is executed. Once the execution completes, al...
Calling a rest service with spring rest + json jackson Presenting to you step by step a tutorial about the use of some apis that leverage the logic for calling to a rest service and also the json parting and marshalling process First Step Importing required libs: You will need to import spring for droid there are the files: spring-android-auth-1.0.0.M4.jar spring-android-core-1.0.0.M4.jar spring-android-rest-template-1.0.0.M4.jar You will need to import jackson lib there is the file: jackson-all-1.9.4.jar Second Step : Declaring variables You will need these three variables to do the trick. I will recomend to declare them as fields and instantiate them later on class constructor. RestTemplate restTemplate = new RestTemplate(); ObjectMapper objectMapper = new ObjectMapper(); JsonFactory jsonFactory = new JsonFactory(); Third step: Calling rest service: Just call this method of rest template and the api will call the service and will encapsulate all the stream st...