Thursday, October 1, 2015
JAVA - when WeakReference and SoftReference are equaly garbage collected
WeakReference - is ALWAYS eagerly garbage collected.
SoftReference - is LESS eagerly garbage collected on Server JVM.
The Sun JRE does treat SoftReferences differently from WeakReferences. We attempt to hold on to object referenced by a SoftReference if there isn't pressure on the available memory. One detail: the policy for the "-client" and "-server" JRE's are different: the -client JRE tries to keep your footprint small by preferring to clear SoftReferences rather than expand the heap, whereas the -server JRE tries to keep your performance high by preferring to expand the heap (if possible) rather than clear SoftReferences. One size does not fit all.
More here...
SoftReference - is LESS eagerly garbage collected on Server JVM.
The Sun JRE does treat SoftReferences differently from WeakReferences. We attempt to hold on to object referenced by a SoftReference if there isn't pressure on the available memory. One detail: the policy for the "-client" and "-server" JRE's are different: the -client JRE tries to keep your footprint small by preferring to clear SoftReferences rather than expand the heap, whereas the -server JRE tries to keep your performance high by preferring to expand the heap (if possible) rather than clear SoftReferences. One size does not fit all.
More here...
JAVA - collections, the main difference between Map and SortedMap contracts
The main difference between Map and SortedMap contracts is its approach to comparing of keys.
Map contract is to compare keys with equals method.
SortedMap contract is to compare keys with provided or class natural compator.
From javadoc of Comparable<T> interface: This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.
Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.
Why NULL can not be set as value in Set?
The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.
Map contract is to compare keys with equals method.
SortedMap contract is to compare keys with provided or class natural compator.
From javadoc of Comparable<T> interface: This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.
Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.
Why NULL can not be set as value in Set?
The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false.
Wednesday, September 30, 2015
GIT - 'git reset' my explanation
When and how to use git reset.
Case 1:
You have commited changes, but not yet pushed it. (never reset shared (pushed) commits, read this)
AND
You want to undo this commit and continue to work on these changes in it.
git reset --soft HEAD~1
Case 2:
You have commited changes, but not yet pushed it. (never reset shared (pushed) commits, read this)
AND
You want to undo this commit and DO NOT WANT to continue to work on these changes in it.
git reset --hard HEAD~1
In this case all changes of this commit will be lost and you will not see it in your Local Changes list (e.g. in InteleJIdea IDE)
HEAD~1 means 'one commit from HEAD'
Case 1:
You have commited changes, but not yet pushed it. (never reset shared (pushed) commits, read this)
AND
You want to undo this commit and continue to work on these changes in it.
git reset --soft HEAD~1
Case 2:
You have commited changes, but not yet pushed it. (never reset shared (pushed) commits, read this)
AND
You want to undo this commit and DO NOT WANT to continue to work on these changes in it.
git reset --hard HEAD~1
In this case all changes of this commit will be lost and you will not see it in your Local Changes list (e.g. in InteleJIdea IDE)
HEAD~1 means 'one commit from HEAD'
Tuesday, September 29, 2015
Friday, September 25, 2015
Thursday, September 24, 2015
Tuesday, September 22, 2015
THREAD - how to stop running thread
private volatile Thread blinker;
public void stop() {
blinker = null;
}
public void run() {
Thread thisThread = Thread.currentThread();
while (blinker == thisThread) {
try {
Thread.sleep(interval);
} catch (InterruptedException e){
}
repaint();
}
}
http://docs.oracle.com/javase/7/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html
Subscribe to:
Posts (Atom)
