Mohinish's Blog

Rants from a technologically confused mind !!

Awesome read: Visual Guide to Nosql Systems

Visual Guide to NoSQL Systems

http://blog.nahurst.com/visual-guide-to-nosql-systems

Written by rootedlabs

December 19, 2011 at 10:10 pm

Posted in Miscellaneous

A Comparison of java.net.URLConnection and HTTPClient

Good Comparision between above 2:

http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html

Written by rootedlabs

November 30, 2011 at 12:27 am

Posted in Java

Progress Listeners for your firefox plugin !!

Following are some sample code snippets and links to make use of to write awesome firefox plugins:

Progress Listeners allow extensions to be notified of events associated with documents loading in the browser and with tab switching events. Progress listeners implement the nsIWebProgressListener interface.

https://developer.mozilla.org/en/Code_snippets/Progress_Listeners

Written by rootedlabs

October 13, 2011 at 6:37 pm

Posted in Java

Good Read: Producer Consumer Example

Reference:

http://www.cin.ufpe.br/~java/docs/tutorial/essential/threads/synchronization.html

Gives an example of Producer Consumer using java threads and synchronization and then via lock from the concurrency package

Written by rootedlabs

September 26, 2011 at 10:52 pm

Posted in Java

Good Read: Non Blocking Algorithm, Non Blocking Stack / LinkedQueue

Java theory and practice: Introduction to nonblocking algorithms
Reference: http://www.ibm.com/developerworks/java/library/j-jtp04186/index.html


public class ConcurrentStack {
AtomicReference<Node> head = new AtomicReference<Node>();

public void push(E item) {
Node newHead = new Node(item);
Node oldHead;
do {
oldHead = head.get();
newHead.next = oldHead;
} while (!head.compareAndSet(oldHead, newHead));
}

public E pop() {
Node oldHead;
Node newHead;
do {
oldHead = head.get();
if (oldHead == null)
return null;
newHead = oldHead.next;
} while (!head.compareAndSet(oldHead,newHead));
return oldHead.item;
}

static class Node {
final E item;
Node next;

public Node(E item) { this.item = item; }
}
}

Written by rootedlabs

September 26, 2011 at 4:25 am

Posted in Java

Good Read: Immutable and Defensive Copies

Been reading java concurrency blog @ www.vogella.de
Ref: http://www.vogella.de/articles/JavaConcurrency/article.html#memorymodel_atomic

1. Immutability

The simplest way to avoid problems with concurrency is to share only immutable data between threads. Immutable data is data which can not changed.

To make a class immutable make

- all its fields final
- the class declared as final
- the this reference is not allowed to escape during construction

Any fields which refer to mutable data objects are

- private
- have no setter method
- they are never directly returned of otherwise exposed to a caller
- if they are changed internally in the class this change is not visible and has no effect outside of the class

An immutable class may have some mutable data which is uses to manages its state but from the outside this class nor any attribute of this classes can get changed.

For all mutable fields, e.g. Arrays, that are passed from the outside to the class during the construction phase, the class needs to make a defensive-copy of the elements to make sure that no other object from the outside still can change the data

2. Defensive Copies

You must protected your classes from calling code. Assume that calling code will do its best to change your data in a way you didn’t expect it. While this is especially true in case of immutable data it is also true for non-immutable data which you still not expect that this data is changed outside your class.

To protect your class against that you should copy data you receive and only return copies of data to calling code.

The following example creates a copy of a list (ArrayList) and returns only the copy of the list. This way the client of this class cannot remove elements from the list.



package de.vogella.performance.defensivecopy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MyDataStructure {
List list = new ArrayList();

public void add(String s) {
list.add(s);
}

/**
* Makes a defensive copy of the List and return it
* This way cannot modify the list itself
*
* @return List
*/

public List getList() {
return Collections.unmodifiableList(list);
}
}

Written by rootedlabs

September 26, 2011 at 3:42 am

Posted in Java

Atomic Operations

leave a comment »

Java 1.5 added capability to define atomic variables, e.g AtomicInteger. The word ‘automic’ comes from the concept of Atomic Operations which is a process that is computed as a single unit of work without any interference.

For example, reading and writing a value to a int variable is automic, the value of variable doesnt change during this process, however the operation i++ is not since it involves first reading the value from i and then incrementing it, however the value i may change due to some other thread during the process.

Automic varibles like AutomicInteger maintains this automic feature by providing methods like getAndDecrement(), getAndSet() etc which prevents any other thread to modify the value while executing these methods.

Written by rootedlabs

September 26, 2011 at 3:28 am

Posted in Java

Awesome Blog: HBase, Garbage Collection

Good Read

http://www.cloudera.com/blog/2011/02/avoiding-full-gcs-in-hbase-with-memstore-local-allocation-buffers-part-1/

Written by rootedlabs

September 13, 2011 at 6:07 am

Posted in MySQL

Some Good Sites on AVL Trees

http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_avl.aspx

http://www.cs.jhu.edu/~goodrich/dsa/trees/avltree.html

Written by rootedlabs

September 3, 2011 at 1:32 am

Posted in Miscellaneous

Awesome resume building and Interview tips

Found a good read on awesome resume writing and interviewing tips:

http://paultyma.blogspot.com/2007/03/howto-pass-silicon-valley-software.html

http://steve-yegge.blogspot.com/2007/09/ten-tips-for-slightly-less-awful-resume.html

Written by rootedlabs

June 13, 2011 at 6:17 pm

Follow

Get every new post delivered to your Inbox.