Get Current Date and Time in a Specific Timezone (Java)

Continue reading

Install Java 8 (JDK 8u66) on CentOS

Download latest 64 bit Java SE Development Kit 8 release

Continue reading

Queue example in Java

Java provides us Queue interface, where we can keep and handle elements before processing. Except the methods that Collection provides, it also supports some basic operations in order to simulate the classic queue structure. Each of these operations exists in two forms:

1. if a method fails, an exception is thrown. This form includes add(), remove() and element() methods.
2. if a method fails, a special value is returned (null or false). This form contains offer(), poll() and peek() operations.
Continue reading

Lock in Java

In the previous post (Synchronized vs ReentrantLock in Java) ,  we have discussed the difference between synchronized and ReentrantLock. The keyword synchronized can be widely used in many multi-threaded environments. However, there are some drawbacks when using synchronized. The use of keyword synchronized provides access to the implicit monitor lock associated with every object, but forces all lock acquisition and release to occur in a block-structured way: when multiple locks are acquired they must be released in the opposite order, and all locks must be released in the same lexical scope in which they were acquired. In short, when the keyword synchronized locks a block, and a thread is in the block, other threads have to wait and will be blocked until that thread exits the block. It will slow down the performance. In some situations, it may leads to a deadlock. Continue reading